-
Notifications
You must be signed in to change notification settings - Fork 0
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
Casey Britt
committed
Jun 25, 2017
0 parents
commit 6ce2850
Showing
3 changed files
with
69 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
node_modules/ |
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,52 @@ | ||
const httpAgent = require('socks5-http-client/lib/Agent'); | ||
const httpsAgent = require('socks5-https-client/lib/Agent'); | ||
|
||
const getAgent = (proxy, type, url) => { | ||
const options = {}; | ||
let user = null; | ||
let pass = null; | ||
let host = null; | ||
let port = null; | ||
|
||
if (proxy.split('@').length > 1) { | ||
user = proxy.split('@')[0].split(':')[0]; | ||
pass = proxy.split('@')[0].split(':')[1]; | ||
host = proxy.split('@')[1].split(':')[0]; | ||
port = proxy.split('@')[1].split(':')[1]; | ||
} else { | ||
host = proxy.split(':')[0]; | ||
port = proxy.split(':')[1]; | ||
} | ||
|
||
if (type === 'socks') { | ||
if (url.substr(0, 5) === 'https') { | ||
options.agentClass = httpsAgent; | ||
} else { | ||
options.agentClass = httpAgent; | ||
} | ||
|
||
options.agentOptions = { | ||
socksHost: host, | ||
socksPort: port, | ||
}; | ||
|
||
if (user) { | ||
options.agentOptions.socksUsername = user; | ||
options.agentOptions.socksPassword = pass; | ||
} | ||
} | ||
|
||
if (type === 'http') { | ||
options.proxy = `http://${proxy}`; | ||
} | ||
|
||
if (type === 'https') { | ||
options.proxy = `https://${proxy}`; | ||
} | ||
|
||
return options; | ||
}; | ||
|
||
module.exports = { | ||
getAgent | ||
}; |
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,15 @@ | ||
{ | ||
"name": "auto-proxy-agent", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"socks5-http-client": "^1.0.2", | ||
"socks5-https-client": "^1.2.1" | ||
} | ||
} |