* Issue #11791 fix suffix mapping for non default DefaultServlet usage. Co-authored-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
eafa7ab0d6
commit
e0066a48ba
|
@ -56,6 +56,7 @@ import org.eclipse.jetty.server.handler.ContextHandler;
|
|||
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;
|
||||
|
@ -555,7 +556,16 @@ public class DefaultServlet extends HttpServlet
|
|||
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
|
||||
|
|
|
@ -3487,6 +3487,26 @@ public class DefaultServletTest
|
|||
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
|
||||
{
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
document.write("Hello");
|
Loading…
Reference in New Issue