Fixed the path encoding in ProxyRequestHelper when the character encoding was specifically set on HttpServletRequest.
When the character encoding was set to UTF-8 for example, the path was correctly decoded in PreDecorationFilter but was reencoded in ProxyRequestHelper using the Servlet default ISO-8859-1. This commit uses the character encoding when set and fallback on default.
This commit is contained in:
committed by
Spencer Gibb
parent
1c532d9637
commit
8229eb657e
@@ -288,4 +288,36 @@ public class ProxyRequestHelperTests {
|
||||
assertThat(requestURI, equalTo(encodedURI));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUTF8Url() {
|
||||
String requestURI = "/oléדרעק";
|
||||
String encodedRequestURI = "/ol%C3%A9%D7%93%D7%A8%D7%A2%D7%A7";
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", requestURI);
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
|
||||
RequestContext context = RequestContext.getCurrentContext();
|
||||
context.set("requestURI", requestURI);
|
||||
|
||||
ProxyRequestHelper helper = new ProxyRequestHelper();
|
||||
|
||||
String uri = helper.buildZuulRequestURI(request);
|
||||
|
||||
assertThat(uri, is(encodedRequestURI));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultEncodingUrl() {
|
||||
String requestURI = "/oléדרעק";
|
||||
String encodedRequestURI = "/ol%E9%3F%3F%3F%3F";
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", requestURI);
|
||||
|
||||
RequestContext context = RequestContext.getCurrentContext();
|
||||
context.set("requestURI", requestURI);
|
||||
|
||||
ProxyRequestHelper helper = new ProxyRequestHelper();
|
||||
|
||||
String uri = helper.buildZuulRequestURI(request);
|
||||
|
||||
assertThat(uri, is(encodedRequestURI));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,6 +377,19 @@ public class PreDecorationFilterTests {
|
||||
assertTrue("sensitiveHeaders is wrong: " + sensitiveHeaders,
|
||||
sensitiveHeaders.containsAll(Arrays.asList("x-bar", "x-foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlProperlyDecodedWhenCharacterEncodingIsSet() throws Exception {
|
||||
this.request.setCharacterEncoding("UTF-8");
|
||||
this.properties.setPrefix("/api");
|
||||
this.properties.setStripPrefix(true);
|
||||
this.request.setRequestURI("/api/foo/ol%C3%A9%D7%93%D7%A8%D7%A2%D7%A7");
|
||||
this.routeLocator.addRoute("/foo/**", "foo");
|
||||
RequestContext ctx = RequestContext.getCurrentContext();
|
||||
this.filter.run();
|
||||
String decodedRequestURI = (String) ctx.get("requestURI");
|
||||
assertTrue(decodedRequestURI.equals("/oléדרעק"));
|
||||
}
|
||||
|
||||
private Object getHeader(List<Pair<String, String>> headers, String key) {
|
||||
String value = null;
|
||||
|
||||
Reference in New Issue
Block a user