Skip to content

Commit ffe74ed

Browse files
yosefdindexzero
authored andcommitted
- support unix donain sockets and windows named pipes (socketPath) on node 0.8.x. On node 0.6.x the support was opaque via port, but on the new node, socketPath should be set explicitely.
- avoid adding multiple headers with the same name - fix bug in setting connection
1 parent eee6bab commit ffe74ed

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

lib/node-http-proxy/http-proxy.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
212212
//
213213
// Setup outgoing proxy with relevant properties.
214214
//
215-
outgoing.host = this.target.host;
216-
outgoing.hostname = this.target.hostname;
217-
outgoing.port = this.target.port;
218-
outgoing.agent = this.target.agent;
219-
outgoing.method = req.method;
220-
outgoing.path = req.url;
221-
outgoing.headers = req.headers;
215+
outgoing.host = this.target.host;
216+
outgoing.hostname = this.target.hostname;
217+
outgoing.port = this.target.port;
218+
outgoing.socketPath = this.target.socketPath;
219+
outgoing.agent = this.target.agent;
220+
outgoing.method = req.method;
221+
outgoing.path = req.url;
222+
outgoing.headers = req.headers;
222223

223224
//
224225
// If the changeOrigin option is specified, change the
@@ -237,7 +238,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
237238
//
238239
// Process the `reverseProxy` `response` when it's received.
239240
//
240-
if (response.headers.connection) {
241+
if (!response.headers.connection) {
241242
if (req.headers.connection) { response.headers.connection = req.headers.connection }
242243
else { response.headers.connection = 'close' }
243244
}
@@ -281,7 +282,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
281282
});
282283

283284
// Set the headers of the client response
284-
res.writeHead(response.statusCode, response.headers);
285+
Object.keys(response.headers).forEach(function(key){
286+
res.setHeader(key, response.headers[key]);
287+
});
288+
res.writeHead(response.statusCode);
285289

286290
// If `response.statusCode === 304`: No 'data' event and no 'end'
287291
if (response.statusCode === 304) {

lib/node-http-proxy/routing-proxy.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ RoutingProxy.prototype.add = function (options) {
8585
//
8686
// TODO: Consume properties in `options` related to the `ProxyTable`.
8787
//
88-
options.target = options.target || {};
89-
options.target.host = options.target.host || options.host;
90-
options.target.port = options.target.port || options.port;
91-
options.target.https = this.target && this.target.https ||
92-
options.target && options.target.https;
88+
options.target = options.target || {};
89+
options.target.host = options.target.host || options.host;
90+
options.target.port = options.target.port || options.port;
91+
options.target.socketPath = options.target.socketPath || options.socketPath;
92+
options.target.https = this.target && this.target.https ||
93+
options.target && options.target.https;
9394

9495
//
9596
// Setup options to pass-thru to the new `HttpProxy` instance

0 commit comments

Comments
 (0)