Skip to content

Commit

Permalink
#9910 - handle review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban committed Jul 13, 2023
1 parent 4a2dea1 commit 7002a61
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,8 @@ protected ServletContextHandler initContextHandler(ServletContext servletContext
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
String includedServletPath = (String)req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
String encodedPathInContext = getEncodedPathInContext(req, includedServletPath);
boolean included = includedServletPath != null;
String encodedPathInContext;
if (included)
encodedPathInContext = URIUtil.encodePath(getIncludedPathInContext(req, includedServletPath, isPathInfoOnly(req)));
else if (isPathInfoOnly(req))
encodedPathInContext = URIUtil.encodePath(req.getPathInfo());
else if (req instanceof ServletApiRequest apiRequest)
encodedPathInContext = Context.getPathInContext(req.getContextPath(), apiRequest.getRequest().getHttpURI().getCanonicalPath());
else
encodedPathInContext = Context.getPathInContext(req.getContextPath(), URIUtil.canonicalPath(req.getRequestURI()));

if (LOG.isDebugEnabled())
LOG.debug("doGet(req={}, resp={}) pathInContext={}, included={}", req, resp, encodedPathInContext, included);
Expand Down Expand Up @@ -522,6 +514,18 @@ else if (req instanceof ServletApiRequest apiRequest)
}
}

protected String getEncodedPathInContext(HttpServletRequest req, String includedServletPath)
{
if (includedServletPath != null)
return URIUtil.encodePath(getIncludedPathInContext(req, includedServletPath, !isDefaultMapping(req)));
else if (!isDefaultMapping(req))
return URIUtil.encodePath(req.getPathInfo());
else if (req instanceof ServletApiRequest apiRequest)
return Context.getPathInContext(req.getContextPath(), apiRequest.getRequest().getHttpURI().getCanonicalPath());
else
return Context.getPathInContext(req.getContextPath(), URIUtil.canonicalPath(req.getRequestURI()));
}

@Override
protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
Expand Down Expand Up @@ -1050,7 +1054,7 @@ public String getWelcomeTarget(HttpContent content, Request coreRequest)
// Check whether a Servlet may serve the welcome resource.
if (_welcomeServletMode != WelcomeServletMode.NONE && welcomeTarget == null)
{
if (isPathInfoOnly(getServletRequest(coreRequest)) && !isIncluded(getServletRequest(coreRequest)))
if (!isDefaultMapping(getServletRequest(coreRequest)) && !isIncluded(getServletRequest(coreRequest)))
welcomeTarget = URIUtil.addPaths(getServletRequest(coreRequest).getPathInfo(), welcome);

ServletHandler.MappedServlet entry = _servletContextHandler.getServletHandler().getMappedServlet(welcomeInContext);
Expand Down Expand Up @@ -1195,9 +1199,9 @@ private static boolean isIncluded(HttpServletRequest request)
return request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;
}

private static boolean isPathInfoOnly(HttpServletRequest req)
private static boolean isDefaultMapping(HttpServletRequest req)
{
return req.getHttpServletMapping().getMappingMatch() != MappingMatch.DEFAULT;
return req.getHttpServletMapping().getMappingMatch() == MappingMatch.DEFAULT;
}

/**
Expand Down

0 comments on commit 7002a61

Please sign in to comment.