simple-proxy-agent
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "simple-proxy-agent", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "An simple agent for HTTP and HTTPS through HTTP and SOCKS proxies", | ||
"main": "./src/agent.js", | ||
"engines": { | ||
"node": ">=11.0" | ||
"node": ">=10.0" | ||
}, | ||
@@ -9,0 +9,0 @@ "scripts": { |
@@ -13,3 +13,2 @@ # simple-proxy-agent | ||
* [ ] Configurable timeout | ||
* [ ] Proxy authentication | ||
@@ -39,2 +38,3 @@ | ||
tunnel: true, // If true, will tunnel all HTTPS using CONNECT method | ||
timeout: 5000, // Time in milli-seconds, to maximum wait for proxy connection to establish | ||
}) | ||
@@ -41,0 +41,0 @@ }) |
@@ -9,3 +9,4 @@ const url = require('url'); | ||
options = Object.assign({ | ||
tunnel: true | ||
tunnel: true, | ||
timeout: 5000 | ||
}, options) | ||
@@ -12,0 +13,0 @@ |
@@ -48,12 +48,13 @@ const http = require('http'); | ||
const req = http.request({ | ||
host: this.proxy.host, | ||
host: this.proxy.hostname, | ||
port: this.proxy.port, | ||
method: "CONNECT", | ||
method: 'CONNECT', | ||
path: (options.hostname || options.host) + ":" + options.port, | ||
headers: { | ||
host: options.host | ||
} | ||
}, | ||
timeout: this.options.timeout | ||
}); | ||
req.once("connect", (res, socket, head) => { | ||
req.once('connect', (res, socket, head) => { | ||
const tunnel = tls.connect({ | ||
@@ -68,6 +69,14 @@ socket: socket, | ||
req.once("error", (err) => { | ||
req.once('timeout', () => { | ||
reject(new Error('HTTP CONNECT request timed out')) | ||
}) | ||
req.once('error', (err) => { | ||
reject(err); | ||
}); | ||
req.once('close', () => { | ||
reject(new Error('Tunnel failed. Socket closed prematurely')); | ||
}); | ||
req.end(); | ||
@@ -74,0 +83,0 @@ } else { |
@@ -77,3 +77,3 @@ const url = require('url'); | ||
}, | ||
timeout: 10000 | ||
timeout: this.options.timeout | ||
}) | ||
@@ -80,0 +80,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21159
554