Fix overwriting userRes headers when using userResHeaderDecorator
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.
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!
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?
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