-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: net/http/httputil: can ReverseProxy copy src header to dst header with Set() instead of Add() ? #50730
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
Comments
And I have added the HeadersOverwrite Option by myself. |
CC @neild |
I add a custom way to modify headers, |
This proposal has been added to the active column of the proposals project |
http allows for headers to be specified multiple times for headers that can be combined with a from rfc 2616
For example, duplicate headers are often used for In a response, a good example of using a header multiple times is to set multiple cookies with Set-Cookie, in which mozilla advises:
|
Yes, I can't agree with you anymore. |
It seems clear that ReverseProxy is not right in certain contexts, but we don't know the right path forward for it. Perhaps the right next step is to put this on hold (or decline it) and suggest that people fork ReverseProxy and experiment in their own copies? |
I think it's I who did not read your proposal accurately I personally have no objection to the patch supplied, but I am curious why it can't be handled in Another thought: I personally find myself reaching for I think if the standard library had a simple That's not a perfect solution either, because it likely means that the reverseproxy response needs to be buffered, which may be undesirable, especially for larger requests. |
Actually, I've solved this problem in this way now. But I don't think it's a good solution, because it feels like solving this problem as a special case in certain special requests, rather than solving it from a project common perspective. For example, I need to make sure three things (the middleware, ReverseProxy, response headers which I care about) are compatible with each other to handle the request correctly. From my personal view, I don't think it's a good way for project maintenance. As you mentioned, many frameworks will not buffer the HTTP body considering the performance, which means the middleware will write the headers before Just my personal opinion. |
It seems like we should decline this until we have a clearer idea of a path forward (or a new package). |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
I use Gin Web Framework to code my HTTP Server,
and handling some requests with ReverseProxy.
I registered the CORS in the Gin Middleware before the requests are handled by the ReverseProxy.
However, unfortunately, my ReverseProxy target server also implements the CORS headers,
which results in the CORS headers becoming duplicated,
and causing the response to be refused by the browser which said it got two
Access-Control-Allow-Origin
in the headers.I also came across the same problem when I used the Gin Gzip Middleware in a similar situation.
So I just looked into the source code and found it use the Add() function to copy the headers,
go/src/net/http/httputil/reverseproxy.go
Lines 163 to 169 in d15481b
Maybe it is better to use the Set() function which can replace the existing values?
Or at least I think we need an option to use Add() or Set()?
The text was updated successfully, but these errors were encountered: