Skip to content

Commit 9b3e1eb

Browse files
committed
[fix] fixed passes functions, now 'this' can be used and options are stored on 'this.options'
1 parent 90fb01d commit 9b3e1eb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/http-proxy/passes/ws-incoming.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ var passes = exports;
6464
*
6565
* @param {ClientRequest} Req Request object
6666
* @param {Socket} Websocket
67-
* @param {Object} Options Config object passed to the proxy
6867
*
6968
* @api private
7069
*/
7170

72-
function XHeaders(req, socket, options) {
71+
function XHeaders(req, socket) {
72+
// Now the options are stored on this
73+
var options = this.options;
7374
if(!options.xfwd) return;
7475

7576
var values = {
@@ -92,11 +93,11 @@ var passes = exports;
9293
*
9394
* @param {ClientRequest} Req Request object
9495
* @param {Socket} Websocket
95-
* @param {Object} Options Config object passed to the proxy
9696
*
9797
* @api private
9898
*/
99-
function stream(req, socket, server, head, clb) {
99+
function stream(req, socket, head, clb) {
100+
var server = this;
100101
common.setupSocket(socket);
101102

102103
if (head && head.length) socket.unshift(head);

test/lib-http-proxy-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('lib/http-proxy.js', function() {
122122
proxy.on('error', function (err) {
123123
expect(err).to.be.an(Error);
124124
expect(err.code).to.be('ECONNREFUSED');
125-
proxyServer._server.close();
125+
proxy._server.close();
126126
done();
127127
})
128128

@@ -148,9 +148,7 @@ describe('lib/http-proxy.js', function() {
148148
setTimeout(function () {
149149
res.end('At this point the socket should be closed');
150150
}, 5)
151-
});
152-
153-
source.listen('8080');
151+
}).listen('8080');
154152

155153
var testReq = http.request({
156154
hostname: '127.0.0.1',
@@ -161,6 +159,8 @@ describe('lib/http-proxy.js', function() {
161159
testReq.on('error', function (e) {
162160
expect(e).to.be.an(Error);
163161
expect(e.code).to.be.eql('ECONNRESET');
162+
proxy._server.close();
163+
source.close();
164164
done();
165165
});
166166

0 commit comments

Comments
 (0)