Hello Team - I'm using Spring Cloud: Angel.SR6 and I'm facing an issue when using zuul proxy, when I send url request which has few encoded characters (encoded using UTF-8) and I haven't set any character encoding header in the request, for example as below
/test/1e94cc67-ab4f-4b64-a5dc-f38d42a1a286_Test+-+Copy+%282%29.jpg
so zuul is decoding that url first using default i.e ISO-8859-1, which will be
/test/1e94cc67-ab4f-4b64-a5dc-f38d42a1a286_Test+-+Copy+(2).jpg
But when zuul routes request to actual service then the url should be as original, right ? But I don't see that happening which means I'm seeing url as /test/1e94cc67-ab4f-4b64-a5dc-f38d42a1a286_Test+-+Copy+(2).jpg instead of /test/1e94cc67-ab4f-4b64-a5dc-f38d42a1a286_Test+-+Copy+%282%29.jpg
Is it something I'm doing wrong or it's a bug.
Comment From: ryanjbaxter
Out of curiosity, have you tried to reproduce this with Brixton.SR3?
Comment From: SreekarVanguru
Hello Ryan - yesterday I even tried with Brixton.SR2 in our dev, I see the same issue.
Comment From: ryanjbaxter
Could you try withe the latest release SR4 as well just to confirm?
Comment From: SreekarVanguru
Hello Ryan - I just tried on my local with Brixton.SR4, still I see the same issue.
Before zuul, the url contains 4a6c474c-25c0-4af4-8987-181a6bd92722_Test+-+Copy+%28100%29.jpg
after zuul forwarding, it changes to 4a6c474c-25c0-4af4-8987-181a6bd92722_Test+-+Copy+(100).jpg
Comment From: jebeaudet
Have a look at https://github.com/spring-cloud/spring-cloud-netflix/issues/647. If you encode your url in utf-8, you can't expect zuul to be working if you don't set the character encoding... If you don't set it, it should decode it using ISO-8859-1 and reencode it with the same encoding before sending it to the backend.
Comment From: spencergibb
@SreekarVanguru there have been various changes regarding encoding and zuul, can you try with Brixton.SR6 or Camden.RELEASE?
Comment From: Chinna-SHS
I used the Camden.SR3 and still same issue
Comment From: jebeaudet
Did you set the character encoding header @Chinna-SHS?
Comment From: Chinna-SHS
@jebeaudet
yes. This is what I am setting in my header Accept-Encoding ->UTF-8 Accept-Charset -> UTF-8
This is what I am sending in my postman(or curl) along with above headers. My parameter hello/world is encoded as hello%2Fworld
http://localhost:8080/zuul/hello%2Fworld
ProxyRequestHelper.buildZuulRequestURI method decode the parameter again and convert it as http://localhost:8090/hello/world
Comment From: Chinna-SHS
I did the following step to fix the / issue forwarding to target service.
====Custom implementation to override ProxyRequestHelper.buildZuulRequestURI method====
@Component @Primary
public class ExtendedProxyRequestHelper extends ProxyRequestHelper { @Override public String buildZuulRequestURI(HttpServletRequest request) { RequestContext context = RequestContext.getCurrentContext(); String contextURI = (String) context.get("requestURI"); if (StringUtils.isNotEmpty(contextURI)) { return contextURI; } else { return super.buildZuulRequestURI(request); } }
}
Comment From: vtahlani
@Chinna-SHS thanks, this worked for me.
Comment From: spencergibb
Closing this due to inactivity. Please re-open if there's more to discuss.
Comment From: Dheeraprabhakar
@Chinna-SHS How did you have SimpleHostRoutingFilter call the custom overridden method you've implemented above? I face the same issue where portions of my url path containing "/" get decoded by "SimpleHostRoutingFilter" just before the request is forwarded to the destination.
Eg: This -> https://localhost:8080/application/%2Fblahblah%EFblahblah is forwarded as -> https://localhost:8080/application/blahblah/blahblah
I did the following but they didnt help: 1. explicitly set "setCharacterEncoding("utf-8")" in my request, it didnt help 2. disabled "SimpleHostRoutingFilter" , but the calls are not being forwarded at all.
At this point, it's not an option to upgrade our sprintboot version or zuul version.
@spencergibb
Can you please suggest the easiest route if you are still working on this project?
The rogue line for me is clearly uri = UriUtils.encodePath(contextURI, this.characterEncoding(request)); in ProxyRequestHelper.java. I see that the url is NOT decoded at all by this line, which is strange!!