Issue #3023 redirect to / when pathInfoOnly (#3047)

Issue #3023 redirect to / when pathInfoOnly (#3047)
This commit is contained in:
Greg Wilkins 2018-11-02 16:38:43 +01:00 committed by GitHub
parent af7dba1249
commit 3995cd2ec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -226,7 +226,7 @@ public class ResourceService
String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
boolean endsWithSlash=(pathInfo==null?servletPath:pathInfo).endsWith(URIUtil.SLASH);
boolean endsWithSlash=(pathInfo==null?(_pathInfoOnly?"":servletPath):pathInfo).endsWith(URIUtil.SLASH);
boolean checkPrecompressedVariants=_precompressedFormats.length > 0 && !endsWithSlash && !included && reqRanges==null;
HttpContent content=null;
@ -373,7 +373,7 @@ public class ResourceService
throws ServletException, IOException
{
// Redirect to directory
if (!endsWithSlash || (pathInContext.length()==1 && request.getAttribute("org.eclipse.jetty.server.nullPathInfo")!=null))
if (!endsWithSlash)
{
StringBuffer buf=request.getRequestURL();
synchronized(buf)

View File

@ -555,6 +555,14 @@ public class DefaultServletTest
altholder.setInitParameter("welcomeServlets", "false");
altholder.setInitParameter("gzip", "false");
ServletHolder otherholder = context.addServlet(DefaultServlet.class, "/other/*");
otherholder.setInitParameter("resourceBase", altRoot.toUri().toASCIIString());
otherholder.setInitParameter("pathInfoOnly", "true");
otherholder.setInitParameter("dirAllowed", "true");
otherholder.setInitParameter("redirectWelcome", "false");
otherholder.setInitParameter("welcomeServlets", "false");
otherholder.setInitParameter("gzip", "false");
ServletHolder defholder = context.addServlet(DefaultServlet.class, "/");
defholder.setInitParameter("dirAllowed", "false");
defholder.setInitParameter("redirectWelcome", "false");
@ -567,6 +575,12 @@ public class DefaultServletTest
String rawResponse;
HttpTester.Response response;
// Test other redirect
rawResponse = connector.getResponse("GET /context/other HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "http://0.0.0.0/context/other/"));
// Test alt default
rawResponse = connector.getResponse("GET /context/alt/dir/ HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);