Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged fixes from all previous pull requests #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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.
17 changes: 11 additions & 6 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 @@ -156,8 +161,7 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
connectReq.removeAllListeners()
socket.removeAllListeners()

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)
Expand All @@ -166,6 +170,7 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
var error = new Error('tunneling socket could not be established, ' + 'statusCode=' + res.statusCode)
error.code = 'ECONNRESET'
options.request.emit('error', error)
socket.destroy()
self.removeSocket(placeholder)
}
}
Expand Down Expand Up @@ -200,7 +205,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