I've been trying to reverse proxy some of my requests internally with httputil.NewSingleHostReverseProxy(*Url)
I noticed that gorilla mux is not happy with this so I found a fix online that solved the issue for GET
requests. However, it seems like like GET
is the only request that will be reverse proxied correctly.
u = generated URL with url.Parse
api.Path("/feature").Methods("POST").HandlerFunc(handler(httputil.NewSingleHostReverseProxy(u)))
func handler(p *httputil.ReverseProxy) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = mux.Vars(r)["path"]
p.ServeHTTP(w, r)
}
}
This works fine for GET
requests, but when sending a POST
or PATCH
the receiving http method is set as GET
. I have confirmed that the proxy's r.Method
is POST
on one end and GET
on the other. Has anyone encountered this issue before, or know what could be causing this?
This error was caused by the route returning a 301 still unclear why. ReverseProxy's fallback behavior on 301, 302, 303 is to support RFC 2616
https://github.com/golang/go/issues/18570 This rewrites the Method to GET