-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
How to escape question mark in proxy rewrite #1798
Comments
I think this relates to #1799 and url.Path/RawPath |
I think so too. The rewrite should be considered as an already escaped URL path, otherwise it will be hard to support an URL with query params, which is a valid usecase. |
Should be fixed by #1799 and the upcoming echo v4.2.1 |
@lammel |
In that case the added unit tests do not reflect the real world and are based on a wrong assumption. |
@eloo could you provide example For example when I try on master func main() {
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
url := r.URL.String()
fmt.Println(url)
w.Write([]byte(url + "\n"))
}))
defer upstream.Close()
url, _ := url.Parse(upstream.URL)
rrb := middleware.NewRoundRobinBalancer([]*middleware.ProxyTarget{{Name: "upstream", URL: url}})
e := echo.New()
e.Use(middleware.ProxyWithConfig(middleware.ProxyConfig{
Balancer: rrb,
Rewrite: map[string]string{
"^/a/*": "/v1/$1",
},
}))
e.Start(":8080")
} I'll send 1 request x@x:~/code/echo curl -v "http://localhost:8080/a/test/pull-requests?role=AUTHOR&limit=1000"
* Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /a/test/pull-requests?role=AUTHOR&limit=1000 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 46
< Content-Type: text/plain; charset=utf-8
< Date: Mon, 08 Mar 2021 08:09:41 GMT
<
/v1/test/pull-requests?role=AUTHOR&limit=1000
* Connection #0 to host localhost left intact In application out ____ __
/ __/___/ / ___
/ _// __/ _ \/ _ \
/___/\__/_//_/\___/ v4.2.1
High performance, minimalist Go web framework
https://echo.labstack.com
____________________________________O/_______
O\
⇨ http server started on [::]:8080
/v1/test/pull-requests?role=AUTHOR&limit=1000
|
@aldas I think the issue here is that the query params are set within the replacement string of a rewrite rule (not the input URL being processed by the rule) appending |
ok, I see now |
problem is that Probably could be fixed in rewritePath by doing path := replacer.Replace(v)
req.URL, _ = req.URL.Parse(path) This way path and query parts are set correctly from replaced path |
I think that should work. The unit tests I added yesterday for in |
@lammel not sure how i can tests a PR? but for the code it looks better.. at least there seems to be a test which should cover my use case |
I usually check out echo locally and use the repo/branch of the PR and use the
And then edit your
(I hope I made no typos, just out of my head) |
@lammel and yes it looks like the bug will be fixed with the PR. Thanks |
Issue Description
Hi,
im currently trying to something with the proxy middleware and i want to proxy a redirect to an upstream url and i want to automatically append some parameters.
But sadly the question mark (?) to indicate that now parameters are following is automatically encoded in the proxy and so my upstream is not accepting it as parameter start.
Checklist
Expected behaviour
My request is forwarded like this
Actual behaviour
the question mark in my request is escaped
Steps to reproduce
Working code to debug
Version/commit
Version: 4.2.0
Thanks
The text was updated successfully, but these errors were encountered: