Skip to content

Fix overwriting userRes headers when using userResHeaderDecorator #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fabb
Copy link

@fabb fabb commented Aug 17, 2024

fixes #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 fabb changed the title avoid overwriting userRes headers when using userResHeaderDecorator Fix overwriting userRes headers when using userResHeaderDecorator Aug 17, 2024
@monkpow
Copy link
Collaborator

monkpow commented May 2, 2025

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!

@fabb
Copy link
Author

fabb commented May 5, 2025

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
Copy link
Author

fabb commented May 5, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

copyProxyResHeadersToUserRes overwrites Set-Cookie headers that have already been set by previous middleware
2 participants