Skip to content

Commit

Permalink
0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamper committed Nov 25, 2018
1 parent eb2b1b1 commit 5c44932
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tunnel-agent
============

HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.
HTTP proxy tunneling agent. Formerly part of request/request, now a standalone module.
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var net = require('net')
, tls = require('tls')
, http = require('http')
, https = require('https')
, events = require('events')
, assert = require('assert')
, util = require('util')
, Buffer = require('safe-buffer').Buffer
;
Expand Down Expand Up @@ -68,7 +66,7 @@ function TunnelingAgent(options) {
self.removeSocket(socket)
})
}
util.inherits(TunnelingAgent, events.EventEmitter)
util.inherits(TunnelingAgent, http.Agent)

TunnelingAgent.prototype.addRequest = function addRequest(req, options) {
var self = this
Expand Down Expand Up @@ -123,6 +121,10 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
{ method: 'CONNECT'
, path: options.host + ':' + options.port
, agent: false
, headers: {
host: options.host + ':' + options.port
}
, servername: self.proxyOptions.host
}
)
if (connectOptions.proxyAuth) {
Expand All @@ -138,6 +140,9 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
connectReq.once('upgrade', onUpgrade) // for v0.6
connectReq.once('connect', onConnect) // for v0.7 or later
connectReq.once('error', onError)
connectReq.setTimeout(options.timeout || 15000, function(){
connectReq.abort();
});
connectReq.end()

function onResponse(res) {
Expand All @@ -155,18 +160,17 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
function onConnect(res, socket, head) {
connectReq.removeAllListeners()
socket.removeAllListeners()
self.sockets[self.sockets.indexOf(placeholder)] = socket

if (res.statusCode === 200) {
assert.equal(head.length, 0)
if (res.statusCode === 200 && head.length == 0) {
debug('tunneling connection has established')
self.sockets[self.sockets.indexOf(placeholder)] = socket
cb(socket)
} else {
debug('tunneling socket could not be established, statusCode=%d', res.statusCode)
var error = new Error('tunneling socket could not be established, ' + 'statusCode=' + res.statusCode)
error.code = 'ECONNRESET'
options.request.emit('error', error)
self.removeSocket(placeholder)
cb(socket)
options.request.emit('error', error) // fire up error on ClientRequest.
}
}

Expand Down Expand Up @@ -200,7 +204,7 @@ function createSecureSocket(options, cb) {
TunnelingAgent.prototype.createSocket.call(self, options, function(socket) {
// 0 is dummy port for v0.6
var secureSocket = tls.connect(0, mergeOptions({}, self.options,
{ servername: options.host
{ servername: self.options.servername || options.host
, socket: socket
}
))
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"author": "Mikeal Rogers <[email protected]> (http://www.futurealoof.com)",
"name": "tunnel-agent",
"license": "Apache-2.0",
"description": "HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.",
"version": "0.6.1",
"description": "HTTP proxy tunneling agent. Formerly part of request/request, now a standalone module.",
"version": "0.6.2",
"repository": {
"url": "https://github.com/mikeal/tunnel-agent"
"url": "https://github.com/request/tunnel-agent"
},
"main": "index.js",
"files": [
"index.js"
],
"dependencies": {
"safe-buffer": "^5.0.1"
"safe-buffer": "^5.1.2"
},
"devDependencies": {},
"optionalDependencies": {},
Expand Down

0 comments on commit 5c44932

Please sign in to comment.