Skip to content

Commit 5c44932

Browse files
committed
0.6.2
1 parent eb2b1b1 commit 5c44932

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tunnel-agent
22
============
33

4-
HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.
4+
HTTP proxy tunneling agent. Formerly part of request/request, now a standalone module.

index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ var net = require('net')
44
, tls = require('tls')
55
, http = require('http')
66
, https = require('https')
7-
, events = require('events')
8-
, assert = require('assert')
97
, util = require('util')
108
, Buffer = require('safe-buffer').Buffer
119
;
@@ -68,7 +66,7 @@ function TunnelingAgent(options) {
6866
self.removeSocket(socket)
6967
})
7068
}
71-
util.inherits(TunnelingAgent, events.EventEmitter)
69+
util.inherits(TunnelingAgent, http.Agent)
7270

7371
TunnelingAgent.prototype.addRequest = function addRequest(req, options) {
7472
var self = this
@@ -123,6 +121,10 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
123121
{ method: 'CONNECT'
124122
, path: options.host + ':' + options.port
125123
, agent: false
124+
, headers: {
125+
host: options.host + ':' + options.port
126+
}
127+
, servername: self.proxyOptions.host
126128
}
127129
)
128130
if (connectOptions.proxyAuth) {
@@ -138,6 +140,9 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
138140
connectReq.once('upgrade', onUpgrade) // for v0.6
139141
connectReq.once('connect', onConnect) // for v0.7 or later
140142
connectReq.once('error', onError)
143+
connectReq.setTimeout(options.timeout || 15000, function(){
144+
connectReq.abort();
145+
});
141146
connectReq.end()
142147

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

159-
if (res.statusCode === 200) {
160-
assert.equal(head.length, 0)
165+
if (res.statusCode === 200 && head.length == 0) {
161166
debug('tunneling connection has established')
162-
self.sockets[self.sockets.indexOf(placeholder)] = socket
163167
cb(socket)
164168
} else {
165169
debug('tunneling socket could not be established, statusCode=%d', res.statusCode)
166170
var error = new Error('tunneling socket could not be established, ' + 'statusCode=' + res.statusCode)
167171
error.code = 'ECONNRESET'
168-
options.request.emit('error', error)
169-
self.removeSocket(placeholder)
172+
cb(socket)
173+
options.request.emit('error', error) // fire up error on ClientRequest.
170174
}
171175
}
172176

@@ -200,7 +204,7 @@ function createSecureSocket(options, cb) {
200204
TunnelingAgent.prototype.createSocket.call(self, options, function(socket) {
201205
// 0 is dummy port for v0.6
202206
var secureSocket = tls.connect(0, mergeOptions({}, self.options,
203-
{ servername: options.host
207+
{ servername: self.options.servername || options.host
204208
, socket: socket
205209
}
206210
))

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
"author": "Mikeal Rogers <mikeal.rogers@gmail.com> (http://www.futurealoof.com)",
33
"name": "tunnel-agent",
44
"license": "Apache-2.0",
5-
"description": "HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.",
6-
"version": "0.6.1",
5+
"description": "HTTP proxy tunneling agent. Formerly part of request/request, now a standalone module.",
6+
"version": "0.6.2",
77
"repository": {
8-
"url": "https://github.com/mikeal/tunnel-agent"
8+
"url": "https://github.com/request/tunnel-agent"
99
},
1010
"main": "index.js",
1111
"files": [
1212
"index.js"
1313
],
1414
"dependencies": {
15-
"safe-buffer": "^5.0.1"
15+
"safe-buffer": "^5.1.2"
1616
},
1717
"devDependencies": {},
1818
"optionalDependencies": {},

0 commit comments

Comments
 (0)