Open syndbg opened 5 years ago
Change https://golang.org/cl/171577 mentions this issue: httputil: add ModifyRequest hook
CC @bradfitz
This doesn't enable anything new. It only seems to add another way to do things and requires a bunch more docs. Maybe you could just add an example to the docs showing how to wrap a Director
func to do the modifications of the request before or after an existing Director.
@bradfitz
Maybe you could just add an example to the docs showing how to wrap a Director func to do the modifications of the request before or after an existing Director.
Sounds, interesting.
If I understand your point correctly,
forwardProxy := httputil.NewSingleHostReverseProxy(target)
originalDirector := forwardProxy.Director
forwardProxy.Director = func(req *http.Request) {
originalDirector(req)
// NOTE: Custom developer logic just begins to start here
...
}
...
Certainly not the prettiest thing out there, but it sure gets the job done and I think everyone can be happy about it.
From what I see it solves the:
Cons:
* More than one way to do things.
* Needs a bit better documentation to signify the difference between Director and ModifyRequest.
@bradfitz Just to be sure that I don't misunderstand the contribution flow here, I'll:
Just to be sure that I don't misunderstand the contribution flow here, I'll:
- Rename the issue and content
- Update the referenced PR's title and patch to only update the docs
Sounds good to me.
Change https://golang.org/cl/172020 mentions this issue: net/http/httputil: add example for reuse of Director
@bradfitz ping https://go-review.googlesource.com/c/go/+/171577
Thank you @syndbg, I've added some feedback to your CL but we are almost there, please take a look.
Not a bug, it's a
API change proposaldocumentation enhancement:Rationale
Since go1.12 enhanced further the ReverseProxy implementation a closed source library (and many more open-source ones) that provide a reverse proxy for HTTP and WS can be deprecated.
The only difference between the closed source library was that I had a more convenient hook to modify a request that allowed me to focus only on the VHOST logic.
The change here would noticeably reduce the boilerplate and make developers avoid re-implementing logic and private function(s) that Directory already implements/uses.
Update: As per discussion, documentation is going to be enhanced. Ref: https://github.com/golang/go/issues/31406#issuecomment-482354227
So, in terms of Golang code
Current state:
(Not needed) With an addition of
ModifyRequest
hookDocumentation to be updated with
In pros/cons based on what I see (with respect to the fact that I'm just a Golang-using developer):
Pros
reverse_proxy
.Director
.Cons
* More than one way to do things.* Needs a bit better documentation to signify the difference betweenDirector
andModifyRequest
.ref: #31393
cc: @agnivade