Skip welcomeServlet logic if requestTarget

does not resolve.
This commit is contained in:
Joakim Erdfelt 2022-10-17 15:21:04 -05:00
parent 1b790d51b4
commit 6ab8aa8d30
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 16 additions and 13 deletions

View File

@ -963,22 +963,25 @@ public class DefaultServlet extends HttpServlet
String requestTarget = isPathInfoOnly() ? request.getPathInfo() : coreRequest.getPathInContext();
Resource base = _baseResource.resolve(requestTarget);
String welcomeServlet = null;
for (String welcome : welcomes)
Resource base = _baseResource.resolve(requestTarget);
if (base != null && base.exists())
{
Resource welcomePath = base.resolve(welcome);
String welcomeInContext = URIUtil.addPaths(coreRequest.getPathInContext(), welcome);
if (welcomePath != null && welcomePath.exists())
return welcomeInContext;
if ((_welcomeServlets || _welcomeExactServlets) && welcomeServlet == null)
for (String welcome : welcomes)
{
ServletHandler.MappedServlet entry = _servletContextHandler.getServletHandler().getMappedServlet(welcomeInContext);
if (entry != null && entry.getServletHolder().getServletInstance() != DefaultServlet.this &&
(_welcomeServlets || (_welcomeExactServlets && entry.getPathSpec().getDeclaration().equals(welcomeInContext))))
welcomeServlet = welcomeInContext;
Resource welcomePath = base.resolve(welcome);
String welcomeInContext = URIUtil.addPaths(coreRequest.getPathInContext(), welcome);
if (welcomePath != null && welcomePath.exists())
return welcomeInContext;
if ((_welcomeServlets || _welcomeExactServlets) && welcomeServlet == null)
{
ServletHandler.MappedServlet entry = _servletContextHandler.getServletHandler().getMappedServlet(welcomeInContext);
if (entry != null && entry.getServletHolder().getServletInstance() != DefaultServlet.this &&
(_welcomeServlets || (_welcomeExactServlets && entry.getPathSpec().getDeclaration().equals(welcomeInContext))))
welcomeServlet = welcomeInContext;
}
}
}
return welcomeServlet;