Commit 982288ec by kakawait Committed by Spencer Gibb

Removing multiple successive slashes

Eliminates zuul URISyntaxException if route has trailing slash. fixes gh-583
parent 804abb6d
...@@ -241,7 +241,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter { ...@@ -241,7 +241,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
requestEntity); requestEntity);
URL host = RequestContext.getCurrentContext().getRouteHost(); URL host = RequestContext.getCurrentContext().getRouteHost();
HttpHost httpHost = getHttpHost(host); HttpHost httpHost = getHttpHost(host);
uri = StringUtils.cleanPath(host.getPath() + uri); uri = StringUtils.cleanPath((host.getPath() + uri).replaceAll("/{2,}", "/"));
HttpRequest httpRequest; HttpRequest httpRequest;
switch (verb.toUpperCase()) { switch (verb.toUpperCase()) {
case "POST": case "POST":
......
...@@ -16,13 +16,11 @@ ...@@ -16,13 +16,11 @@
package org.springframework.cloud.netflix.zuul; package org.springframework.cloud.netflix.zuul;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -64,6 +62,9 @@ import com.netflix.loadbalancer.ServerList; ...@@ -64,6 +62,9 @@ import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleZuulProxyApplication.class) @SpringApplicationConfiguration(classes = SampleZuulProxyApplication.class)
@WebAppConfiguration @WebAppConfiguration
...@@ -189,6 +190,17 @@ public class SampleZuulProxyApplicationTests { ...@@ -189,6 +190,17 @@ public class SampleZuulProxyApplicationTests {
} }
@Test @Test
public void simpleHostRouteWithTrailingSlash() {
routes.addRoute("/self/**", "http://localhost:" + this.port + "/");
this.endpoint.reset();
ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/self/trailing-slash",
HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("/trailing-slash", result.getBody());
}
@Test
public void ribbonCommandFactoryOverridden() { public void ribbonCommandFactoryOverridden() {
assertTrue("ribbonCommandFactory not a MyRibbonCommandFactory", assertTrue("ribbonCommandFactory not a MyRibbonCommandFactory",
ribbonCommandFactory instanceof SampleZuulProxyApplication.MyRibbonCommandFactory); ribbonCommandFactory instanceof SampleZuulProxyApplication.MyRibbonCommandFactory);
...@@ -246,6 +258,11 @@ class SampleZuulProxyApplication { ...@@ -246,6 +258,11 @@ class SampleZuulProxyApplication {
return "Hello space"; return "Hello space";
} }
@RequestMapping(value = "/trailing-slash")
public String trailingSlash(HttpServletRequest request) {
return request.getRequestURI();
}
@Bean @Bean
public RibbonCommandFactory ribbonCommandFactory(SpringClientFactory clientFactory) { public RibbonCommandFactory ribbonCommandFactory(SpringClientFactory clientFactory) {
return new MyRibbonCommandFactory(clientFactory); return new MyRibbonCommandFactory(clientFactory);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment