-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: net/http/httputil: add a ModifyRequest method to ReverseProxy #45469
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
Change https://golang.org/cl/295390 mentions this issue: |
I do not support this change, literally Director is not the same as ModifyRequest, I want ModifyRequest to be like an optional handler, used before or after Director. |
How would that work? What would
I was initially thinking of a different approach, adding a Since the director's role is to modify the request, and there is already a I am in no way saying this is the best way to do it, just the best way I could come up with. If there is a more fitting approach, I'm certainly open to suggestions and would like to help make it happen, since not being able to interrupt the director without doing some gymnastics is an itch I want to scratch. |
I understand that |
And that is what this proposal is about, making it easier to use ReverseProxy without wrappers/middleware. For anything more complex than changing the destination host and/or basic path rewrites, one requires a wrapper that first of all validates the request can be proxied (e.g. if routing decisions are made by checking some headers or cookies, first step would be to make sure the required headers/cookies are present, or that the URL follows a certain format/matches certain regexps etc). Then the wrapper could modify the request directly, leaving nothing for the director to do, or if the wrapper does validation only, the director would then have to extract the same information again from path/headers/cookies, or be passed that information by the wrapper, e.g. via context. But that would be just to give the director something to do, because it obviously makes sense to have the middleware prepare the request. But that would mean a case could be made the other way around, to remove the Director completely, because it's only useful in the most basic scenarios, and even then a wrapper can be used to modify the request. I believe replacing it with a method that can interrupt the flow adds more flexibility to ReverseProxy, as it could be used without wrappers in more advanced situations as well. |
You can effectively cancel a request in a That said, explicitly returning an error from the request-modification hook is cleaner and more obvious. Also, I think I think adding
|
If we do add |
I don't see what this adds. The caller can look at the request and reject it or modify it before calling the ReverseProxy.ServeHTTP func. |
This proposal has been added to the active column of the proposals project |
This proposal doesn't add new functionality, indeed, it just makes working with ReverseProxy easier (usecases that previously required a wrapper could be handled directly by/in the new method). If the desire is for it to live side-by-side with the current The more I think about it, the more convinced I am that the two changes should come as a whole - a new method that can stop the flow and marking the old one as deprecated, in effect replacing it. Though I'll admit I'm saying that under the assumption that nothing marked as deprecated actually gets removed in Go 1, to preserve backwards compatibility (and the proposed patch actually accounts for that, still calling the |
I don't think we should deprecate an API that has been around for as long as Given that adding a |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
[This has been sitting idle in #44535 for a while, probably because I didn't open an issue to it as well. My apologies for that.]
The
Director()
method doesn't allow reporting an error and/or stop processing a request. This can be worked around with middleware, but that brings about a lot of ceremony and makesReverseProxy
hard to use on its own.The proposed patch in the PR adds a new
ModifyRequest()
method, that supports returning an error. Similar toModifyResponse()
, if an error is returned the normal flow is stopped and the error handler is called instead.In the spirit of having only one way to do things, the PR also deprecates the
Director
field. If noModifyRequest
is given, the oldDirector
is called instead and considered to always succeed, to preserve backwards compatibility (including crashing ifDirector
is also empty).The text was updated successfully, but these errors were encountered: