fix double slashes in eureka server

fixes gh-100
This commit is contained in:
Spencer Gibb
2014-12-11 16:10:55 -07:00
parent a2fade98a5
commit ba6a414d1d
3 changed files with 22 additions and 2 deletions

View File

@@ -69,10 +69,14 @@ public class EurekaController {
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 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("basePath", basePath);

View File

@@ -1,6 +1,7 @@
package org.springframework.cloud.netflix.eureka.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Map;

View File

@@ -1,6 +1,8 @@
package org.springframework.cloud.netflix.eureka.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import java.util.Map;
@@ -54,4 +56,17 @@ public class ApplicationTests {
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+"/"));
}
}