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

Fix overwriting userRes headers when using userResHeaderDecorator

Open fabb opened this issue 1 year ago • 3 comments

fixes https://github.com/villadora/express-http-proxy/issues/547

previously, the proxy response would overwrite same-named headers without the possibility to fix it in userResHeaderDecorator. This is problematic e.g. for applications that use set-cookie for auth cookies set in a middleware before the proxy middleware, and where the proxy response overwrites this header.

this change is backwards-compatible and keeps overwriting headers, but when using userResHeaderDecorator, the original headers can be read from userRes and returned to the caller.

fabb avatar Aug 17 '24 06:08 fabb

Hey @fabb, Thanks for this commit. I believe this is already possible using the feature, and added some tests and documentation to this effect (#548). If you are still interested, let me know if this solves your use case, and if not, what I'm missing. Thanks!

monkpow avatar May 02 '25 21:05 monkpow

hi @monkpow!

unfortunately the existing feature does not solve my use case.

I have a server with multiple middlewares that modify the response before the express-http-proxy middleware runs. one of my middlewares sets one or multiple Set-Cookie headers. this line in express-http-proxy unfortunately overwrites this header: https://github.com/villadora/express-http-proxy/blob/master/app/steps/copyProxyResHeadersToUserRes.js#L13.

So copyProxyResHeadersToUserRes is the culprit, and i don't see a way around it other than modifying it similar to this PR. do you have other ideas?

fabb avatar May 05 '25 07:05 fabb

you can see the desired behavior in this line of the unit tests of this PR: https://github.com/villadora/express-http-proxy/pull/548/files#diff-3f8141190536852cab9b4717bf9c4113f9e6175d047adf09754347b469d8f820R105

fabb avatar May 05 '25 07:05 fabb