chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.7k stars 834 forks source link

fix(websocket): handle errors in handleUpgrade #823

Open nwalters512 opened 2 years ago

nwalters512 commented 2 years ago

Description

When there is an error from user-provided code (pathFilter, rewritePath, or router), that error is now handled and exposed to the user via proxy.emit('error', ...).

error-response-plugin was also updated to handle the fact that it might receive a socket. If it does, it will call socket.destroy().

Motivation and Context

See #822 for a description of the issue being fixed. This PR closes #822.

How has this been tested?

I added a new test case. It fails on master, and works correctly with my new changes.

Types of changes

I'm split on whether or not this should be considered a breaking change. Folks could have written code assuming that the error handler would always get a Response as the third argument, whereas now it would get a Socket. That said, the TypeScript types from http-proxy do reflect that that could be a Socket, so it shouldn't come as too much of a surprise.

Checklist:

nwalters512 commented 2 years ago

@chimurai 👋 can I do anything to help this along?

chimurai commented 1 year ago

Sorry for the late reply. I'll need some time to review 🙏

nwalters512 commented 1 year ago

@chimurai thanks!

nwalters512 commented 7 months ago

@chimurai is there any chance you'd be able to review soon? If so, I'll resolve the merge conflicts with master.