Skip to content

Commit

Permalink
Issue #11791 fix suffix mapping for non default DefaultServlet usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbartel committed May 16, 2024
1 parent a9b2da5 commit 1f5a052
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.eclipse.jetty.util.Blocker;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ExceptionUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.Resources;
Expand Down Expand Up @@ -555,7 +556,13 @@ protected String getEncodedPathInContext(HttpServletRequest req, String included
if (includedServletPath != null)
return encodePath(getIncludedPathInContext(req, includedServletPath, !isDefaultMapping(req)));
else if (!isDefaultMapping(req))
return encodePath(req.getPathInfo());
{
String path = req.getPathInfo();
if (StringUtil.isEmpty(path))
path = req.getServletPath();

return encodePath(path);
}
else if (req instanceof ServletApiRequest apiRequest)
return Context.getPathInContext(req.getContextPath(), apiRequest.getRequest().getHttpURI().getCanonicalPath());
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,26 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
assertThat(response.getContent(), containsString("testPathInfoOnly-OK"));
}

@Test
public void testSuffixMappings() throws Exception
{
server.stop();

Path suffixroot = MavenTestingUtils.getTestResourcePath("suffixroot");
ResourceFactory resourceFactory = ResourceFactory.of(context);
context.setBaseResource(resourceFactory.newResource(suffixroot.toUri()));

ServletHolder holderAlt = new ServletHolder("static-js", DefaultServlet.class);
context.addServlet(holderAlt, "*.js");
ServletHolder holderDef = new ServletHolder("default", DefaultServlet.class);
holderDef.setInitParameter("dirAllowed", "true");
context.addServlet(holderDef, "/");

server.start();
String rawResponse = connector.getResponse("GET /context/test.js HTTP/1.0\r\n\r\n");
assertThat(rawResponse, containsString("Hello"));
}

@Test
public void testMemoryResourceRange() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("Hello");

0 comments on commit 1f5a052

Please sign in to comment.