Commit ba6a414d by Spencer Gibb

fix double slashes in eureka server

fixes gh-100
parent a2fade98
...@@ -69,10 +69,14 @@ public class EurekaController { ...@@ -69,10 +69,14 @@ public class EurekaController {
return map; return map;
} }
private void populateBase(HttpServletRequest request, Map<String, Object> model) { protected void populateBase(HttpServletRequest request, Map<String, Object> model) {
String servletPath = request.getServletPath(); String servletPath = request.getServletPath();
String path = request.getContextPath() + (servletPath==null ? "" : servletPath); String path = request.getContextPath() + (servletPath==null ? "" : servletPath);
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
if (!basePath.endsWith("/")) {
basePath += "/";
}
model.put("time", new Date()); model.put("time", new Date());
model.put("basePath", basePath); model.put("basePath", basePath);
......
package org.springframework.cloud.netflix.eureka.server; package org.springframework.cloud.netflix.eureka.server;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.Map; import java.util.Map;
......
package org.springframework.cloud.netflix.eureka.server; package org.springframework.cloud.netflix.eureka.server;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import java.util.Map; import java.util.Map;
...@@ -54,4 +56,17 @@ public class ApplicationTests { ...@@ -54,4 +56,17 @@ public class ApplicationTests {
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
} }
@Test
public void noDoubleSlashes() {
String basePath = "http://localhost:" + port + "/";
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
basePath, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
String body = entity.getBody();
assertNotNull(body);
assertFalse("basePath contains double slashes", body.contains(basePath+"/"));
}
} }
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