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
…#11799)

* Issue #11791 fix suffix mapping for non default DefaultServlet usage.

Co-authored-by: Greg Wilkins <gregw@webtide.com>
  • Loading branch information
janbartel and gregw authored May 23, 2024
1 parent eafa7ab commit e0066a4
Show file tree
Hide file tree
Showing 3 changed files with 32 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,16 @@ 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());
{
//a match via an extension mapping will more than likely
//have no path info
String path = req.getPathInfo();
if (StringUtil.isEmpty(path) &&
MappingMatch.EXTENSION.equals(req.getHttpServletMapping().getMappingMatch()))
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 e0066a4

Please sign in to comment.