node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

fix request abort for node 16+

Open Matt-Esch opened this issue 3 years ago • 3 comments
trafficstars

After upgrading to node 16, the web proxy stopped working when requests were aborted. The specific use case was SSE where the incoming request has ended but the server response is a long lived http connection. The 'aborted' event and the 'abort' method are deprecated. The response 'close' event and the 'destroy' method are the correct alternatives and pre-date node 8, which is the minimum version this package currently supports. I did run tests on node 8/10/12/14/16 and they failed on node 16 prior to this fix and all pass after this fix.

Matt-Esch avatar Apr 06 '22 02:04 Matt-Esch

Can we merge this?

anthonyalayo avatar Apr 10 '23 18:04 anthonyalayo

Unfortunately won't work in node.js 16 and below since the "close" event was added to in v16:

https://nodejs.org/docs/latest-v16.x/api/http.html#event-close https://nodejs.org/docs/latest-v15.x/api/http.html#event-close

Can't find any info on what's the minimum node version node-http-proxy supports but in this case it should be pretty easy to use "abort" for v15 and below and "close" for v16 and above. That's what https://github.com/http-party/node-http-proxy/pull/1559 does

callumgare avatar May 12 '23 01:05 callumgare

@callumgare I'm not sure I follow. This PR attaches a "close" event listener to res, which is an instance of http.ServerResponse. According to Node.js docs, this event is present in both v16 and v15: https://nodejs.org/docs/latest-v16.x/api/http.html#event-close_2 https://nodejs.org/docs/latest-v15.x/api/http.html#http_event_close_1 Am I missing something?

gdrbyKo1 avatar Apr 19 '24 08:04 gdrbyKo1