This repository has been archived by the owner on May 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,606 additions
and
810 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ node_modules | |
# Users Environment Variables | ||
.lock-wscript | ||
|
||
test.js | ||
test.js | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ node_js: | |
- 8 | ||
- 6 | ||
|
||
sudo: false | ||
sudo: false | ||
|
||
after_success: npm run coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
## Change Log | ||
|
||
### v3.0.0 (07/03/2019) | ||
- **BREAKING CHANGE**: `get/post` methods together with their signatures are aligned with corresponding methods from [request](https://github.com/request/request#requestmethod) | ||
- **BREAKING CHANGE**: `cloudscraper.request` method is deprecated in favour of `cloudscraper(options)` | ||
- Promise support has been added by using `request-promise` | ||
- Error object are inherited from Error and have additional properties. | ||
* `options` - The request options | ||
* `cause` - An alias for `error` | ||
* `response` - The request response | ||
- Stacktraces are available in error objects | ||
- `cloudflareTimeout` option can be defined to speed up waiting time | ||
- Challenge evaluation is done in a sandbox to avoid potential secutiry issues | ||
- Default [request methods](https://github.com/request/request#requestmethod) are available | ||
- Custom cookie jar can now be passed [#103](https://github.com/codemanki/cloudscraper/issues/102) | ||
- Proxies support [PR#101](https://github.com/codemanki/cloudscraper/pull/101) | ||
- MIT license | ||
|
||
### v2.0.1 (02/03/2019) | ||
- Minor documentation changes | ||
|
||
### v2.0.0 (09/12/2018) | ||
- [#2943](https://github.com/codemanki/cloudscraper/pull/66) Support recursive challenge solving. | ||
- **BREAKING CHANGE** Before this, when any error has been detected, the callback was called with an incorrect order: `callback(.., body, response);` instead of `return callback(..., response, body);` | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict'; | ||
|
||
// The purpose of this library is two-fold. | ||
// 1. Have errors consistent with request/promise-core | ||
// 2. Prevent request/promise core from wrapping our errors | ||
|
||
// There are two differences between these errors and the originals. | ||
// 1. There is a non-enumerable errorType attribute. | ||
// 2. The error constructor is hidden from the stacktrace. | ||
|
||
var EOL = require('os').EOL; | ||
var BUG_REPORT = format([ | ||
'### Cloudflare may have changed their technique, or there may be a bug.', | ||
'### Bug Reports: https://github.com/codemanki/cloudscraper/issues', | ||
'### Check the detailed exception message that follows for the cause.' | ||
]); | ||
|
||
var original = require('request-promise-core/errors'); | ||
var OriginalError = original.RequestError; | ||
|
||
var RequestError = create('RequestError', 0); | ||
var CaptchaError = create('CaptchaError', 1); | ||
var CloudflareError = create('CloudflareError', 2); | ||
var ParserError = create('ParserError', 3); | ||
// errorType 4 is a CloudflareError so that constructor is reused. | ||
|
||
// The following errors originate from promise-core and it's dependents. | ||
// Give them an errorType for consistency. | ||
original.StatusCodeError.prototype.errorType = 5; | ||
original.TransformError.prototype.errorType = 6; | ||
|
||
// This replaces the RequestError for all libraries using request/promise-core | ||
// and prevents silent failure. | ||
Object.defineProperty(original, 'RequestError', { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: RequestError | ||
}); | ||
|
||
// Export our custom errors along with StatusCodeError, etc. | ||
Object.assign(module.exports, original, { | ||
RequestError: RequestError, | ||
CaptchaError: CaptchaError, | ||
ParserError: ParserError, | ||
CloudflareError: CloudflareError | ||
}); | ||
|
||
function create(name, errorType) { | ||
function CustomError(cause, options, response) { | ||
|
||
// This prevents nasty things e.g. `error.cause.error` and | ||
// is why replacing the original RequestError is necessary. | ||
if (cause instanceof OriginalError) { | ||
return cause; | ||
} | ||
|
||
OriginalError.apply(this, arguments); | ||
|
||
// Change the name to match this constructor | ||
this.name = name; | ||
|
||
if (this instanceof ParserError) { | ||
this.message = BUG_REPORT + this.message; | ||
} | ||
|
||
if (Error.captureStackTrace) { // required for non-V8 environments | ||
// Provide a proper stack trace that hides this constructor | ||
Error.captureStackTrace(this, CustomError); | ||
} | ||
} | ||
|
||
CustomError.prototype = Object.create(OriginalError.prototype); | ||
CustomError.prototype.constructor = CustomError; | ||
// Keeps things stealthy by defining errorType on the prototype. | ||
// This makes it non-enumerable and safer to add. | ||
CustomError.prototype.errorType = errorType; | ||
|
||
Object.setPrototypeOf(CustomError, Object.getPrototypeOf(OriginalError)); | ||
Object.defineProperty(CustomError, 'name', { | ||
configurable: true, | ||
value: name | ||
}); | ||
|
||
return CustomError; | ||
} | ||
|
||
function format(lines) { | ||
return EOL + lines.join(EOL) + EOL + EOL; | ||
} |
Oops, something went wrong.