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
Proxy route to another backend #686
Comments
Maybe use a middleware to set up a ReverseProxy?
|
Thanks, this worked. But the headers are not being passed to the backend |
Got this sorted out with this: router.POST("/api/v1/endpoint1", ReverseProxy()
func ReverseProxy() gin.HandlerFunc {
target := "localhost:3000"
return func(c *gin.Context) {
director := func(req *http.Request) {
r := c.Request
req = r
req.URL.Scheme = "http"
req.URL.Host = target
req.Header["my-header"] = []string{r.Header.Get("my-header")}
// Golang camelcases headers
delete(req.Header, "My-Header")
}
proxy := &httputil.ReverseProxy{Director: director}
proxy.ServeHTTP(c.Writer, c.Request)
}
} |
Weird. I whipped up a test and I only had to add |
Does this pass cookies? |
Oh sorry, cookies are in the header |
Can we have a chance to manipulate the response? |
@kidambisrinivas you should remove both lines to make it work:
|
How to reverse proxy web requests for a few routes to another backend in Gin Gonic web golang framework
Is there a way to directly forward in the Handle function as shown below?
The text was updated successfully, but these errors were encountered: