You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to escape question mark in proxy rewrite #1798
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.
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.
In that case the added unit tests do not reflect the real world and are based on a wrong assumption.
The request path is actually set correctly, probably the Request-URI is not.
Thanks for the feedback.
@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 ?role=AUTHOR&limit=1000 there when applying the replacement, which seems to be escaped when sending the request to the backend server.
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 rewrite_test.go should be adjusted then to check against the resulting URL (I think I only used the path there, which was the wrong assumption)
Activity
aldas commentedon Mar 4, 2021
I think this relates to #1799 and url.Path/RawPath
lammel commentedon Mar 5, 2021
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.
Add rewrite test for correct escaping of replacement (labstack#1798)
Fix performance regression caused by path escaping (#1777, #1798, #1799)
lammel commentedon Mar 8, 2021
Should be fixed by #1799 and the upcoming echo v4.2.1
eloo commentedon Mar 8, 2021
@lammel
Seems not be fixed in 4.2.1
lammel commentedon Mar 8, 2021
In that case the added unit tests do not reflect the real world and are based on a wrong assumption.
The request path is actually set correctly, probably the Request-URI is not.
Thanks for the feedback.
aldas commentedon Mar 8, 2021
@eloo could you provide example
For example when I try on master
I'll send 1 request
In application out
lammel commentedon Mar 8, 2021
@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
?role=AUTHOR&limit=1000there when applying the replacement, which seems to be escaped when sending the request to the backend server.aldas commentedon Mar 8, 2021
ok, I see now
aldas commentedon Mar 8, 2021
problem is that
role=AUTHOR&limit=1000is not path. this is query part of url.Probably could be fixed in rewritePath by doing
This way path and query parts are set correctly from replaced path
lammel commentedon Mar 8, 2021
I think that should work. The unit tests I added yesterday for in
rewrite_test.goshould be adjusted then to check against the resulting URL (I think I only used the path there, which was the wrong assumption)allow proxy middleware to pass rewritten query part (fix labstack#1798)
allow proxy middleware to pass rewritten query part (fix labstack#1798)
lammel commentedon Mar 9, 2021
@eloo Could you please verify if PR #1802 fixes your issue?
eloo commentedon Mar 9, 2021
@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
lammel commentedon Mar 9, 2021
I usually check out echo locally and use the repo/branch of the PR and use the
replacedirective ofgo.mod.And then edit your
go.mod:(I hope I made no typos, just out of my head)
eloo commentedon Mar 9, 2021
@lammel
thanks for this tip. works like a charm!
and yes it looks like the bug will be fixed with the PR.
Thanks
Allow proxy middleware to use query part in rewrite (fix #1798) (#1802)