Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Loading