node.js version: v20.10.0
node-http-proxy version: v1.18.1
When a client sends a http request with invalid http header (for example “User Agent” without a dash in the middle), the node (built-in) http generates the exception ERR_INVALID_HTTP_TOKEN https://github.com/nodejs/node/blob/v20.x/lib/_http_outgoing.js#L629 which is not handled by node-http-proxy and causes the http proxy to crash. Having proxy.on(‘error’, function(e) {}) does not help.
I already posted an issue in the node-http-proxy project
https://github.com/http-party/node-http-proxy/issues/1679
but am afraid considering the long list of unsolved issues there, this issue could be unlikely viewed soon.
My fix attempt here seems to work:
https://github.com/moky80/node-http-proxy-handle-err-invalid-http-token/commit/3e0a54951473a6940b7f05b26cd007d191d99075
The effect of the fix is server won’t send response if there is a invalid header in requests, but won’t crash and can keeps serving other incoming requests.
Could somebody comment on the fix or recommend a better fix? I would also very much appreciate if the fix is done directly in the project by you. I am just posing the question here because I think there’re more audience on this platform.
2