Skip to content

Commit b652501

Browse files
author
Nicolay Ramm
committed
Don't prematurely close sockets
Don't immediately close the response socket when a `Connection: close` header is received from the target. Instead simply skip the error callback for connection errors on sockets that are supposed to be closed.
1 parent fc95ebc commit b652501

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ web_o = Object.keys(web_o).map(function(pass) {
137137
proxyReq.on('error', proxyError);
138138

139139
function proxyError (err){
140+
if (err.code === 'ECONNRESET' && proxyReq._headers && proxyReq._headers.connection === 'close') {
141+
// The target server has closed the connection, but since it first sent
142+
// a 'Connection: close' header this is not an error.
143+
return;
144+
}
145+
140146
if (clb) {
141147
clb(err, req, res, options.target);
142148
} else {
@@ -147,11 +153,6 @@ web_o = Object.keys(web_o).map(function(pass) {
147153
(options.buffer || req).pipe(proxyReq);
148154

149155
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-
155156
if(server) { server.emit('proxyRes', proxyRes, req, res); }
156157
for(var i=0; i < web_o.length; i++) {
157158
if(web_o[i](req, res, proxyRes, options)) { break; }

0 commit comments

Comments
 (0)