Skip to content
This repository was archived by the owner on Jun 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions examples/example_cookies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import got from 'got';
import { CookieJar } from 'tough-cookie';
const tunnel = require('tunnel');
const parse = require('parse-headers')
const cookie = require('cookie')

import { catchCloudflare } from '../src/index';

// example helper function
async function main() {
// cookie jar is required!
const cookieJar = new CookieJar();
const options = {
// use "url: to describe path
url: 'http://soap2day.is',
cookieJar,
// either disable retry or remove status code 503 from retries
retry: 0,

agent: {
https: tunnel.httpOverHttp({
proxy: {
host: 'ip',
port: 1256,

// Basic authorization for proxy server if necessary
proxyAuth: '',

// Header fields for proxy server if necessary
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36',
},
},
}),
},
};

let res: any;
try {
// success without cloudflare?
// const res = await cloudscraper({
// method: 'GET',
// url: 'https://rlsbb.ru/support-us',
// });
res = await got.get(options);
return res;
} catch (error) {
// success with cloudflare?
res = await catchCloudflare(error, options);
}

return cookie.parse(parse(res.req._header).cookie);
}

main()
.then((res) => console.log(res))
.catch((err) => console.error('fail', err));
169 changes: 165 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
"semantic-release": "semantic-release"
},
"dependencies": {
"cookie": "^0.4.1",
"delay": "^4.3.0",
"got": "^11.0.3"
"got": "^11.0.3",
"parse-headers": "^2.0.3",
"tunnel": "0.0.6"
},
"devDependencies": {
"@pollyjs/adapter-fetch": "4.2.1",
Expand All @@ -62,6 +65,7 @@
"semantic-release": "17.0.7",
"tough-cookie": "4.0.0",
"ts-jest": "25.4.0",
"tsc-watch": "^4.2.3",
"typescript": "3.8.3"
},
"jest": {
Expand Down
6 changes: 3 additions & 3 deletions src/catchCloudflare.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import crypto from 'crypto';
import * as crypto from 'crypto';
import delay from 'delay';
import got, { Response, RequiredRetryOptions } from 'got';
import https from 'https';
import vm from 'vm';
import * as https from 'https';
import * as vm from 'vm';
import { URLSearchParams } from 'url';

const BUG_REPORT = `
Expand Down