Skip to content

Commit fc95ebc

Browse files
author
Nicolay Ramm
committed
Close the connection when target sends "Connection: close" header
This prevents ECONNRESET errors from being thrown for connections that are supposed to be closed (fixes http-party#1000).
1 parent 6baf149 commit fc95ebc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ web_o = Object.keys(web_o).map(function(pass) {
7878
(req.headers['x-forwarded-' + header] ? ',' : '') +
7979
values[header];
8080
});
81-
81+
8282
req.headers['x-forwarded-host'] = req.headers['host'];
8383
},
8484

@@ -147,6 +147,11 @@ web_o = Object.keys(web_o).map(function(pass) {
147147
(options.buffer || req).pipe(proxyReq);
148148

149149
proxyReq.on('response', function(proxyRes) {
150+
// Respect the target server's wish to close the connection
151+
if(proxyRes.headers.connection && proxyRes.headers.connection === 'close') {
152+
proxyRes.connection.destroy();
153+
}
154+
150155
if(server) { server.emit('proxyRes', proxyRes, req, res); }
151156
for(var i=0; i < web_o.length; i++) {
152157
if(web_o[i](req, res, proxyRes, options)) { break; }

0 commit comments

Comments
 (0)