Disable following redirects in SimpleHostRoutingFilter. Fixes #2578. (#2608)

This commit is contained in:
Ryan Baxter
2018-01-03 14:19:39 -05:00
committed by GitHub
parent 9deab33dc1
commit a4c995a394
2 changed files with 21 additions and 1 deletions

View File

@@ -220,7 +220,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
return httpClientFactory.createBuilder().
setDefaultRequestConfig(requestConfig).
setConnectionManager(this.connectionManager).build();
setConnectionManager(this.connectionManager).disableRedirectHandling().build();
}
private CloseableHttpResponse forward(CloseableHttpClient httpclient, String verb,

View File

@@ -196,6 +196,20 @@ public class SimpleHostRoutingFilterTests {
assertTrue("Get 1".equals(responseString));
}
@Test
public void redirectTest() throws Exception {
setupContext();
InputStreamEntity inputStreamEntity = new InputStreamEntity(new ByteArrayInputStream(new byte[]{}));
HttpRequest httpRequest = getFilter().buildHttpRequest("GET", "/app/redirect", inputStreamEntity,
new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(), new MockHttpServletRequest());
CloseableHttpResponse response = getFilter().newClient().execute(new HttpHost("localhost", this.port), httpRequest);
assertEquals(302, response.getStatusLine().getStatusCode());
String responseString = copyToString(response.getEntity().getContent(), Charset.forName("UTF-8"));
assertTrue(response.getLastHeader("Location").getValue().contains("/app/get/5"));
}
@Test
public void zuulHostKeysUpdateHttpClient() {
setupContext();
@@ -259,6 +273,12 @@ class SampleApplication {
public String getString(@PathVariable String id, HttpServletResponse response) throws IOException {
return "Get " + id;
}
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect(HttpServletResponse response) throws IOException {
response.sendRedirect("/app/get/5");
return null;
}
}
class GZIPCompression {