correct DefaultServlet resource pathinContext calculation

exclude servletPath option as resources are always relative to htroot 
or htdocs, the change reflects this.
Theoretically it and the recent adjustments arcording relative urls 
allows to configure the instance to be configurable in a path other as 
root (/)
pull/97/head
reger 8 years ago
parent c50e23c495
commit 0959038624

@ -129,8 +129,6 @@ import com.google.common.util.concurrent.UncheckedTimeoutException;
* *
* resourceBase Set to replace the context resource base * resourceBase Set to replace the context resource base
* *
* pathInfoOnly If true, only the path info will be applied to the resourceBase
*
* </PRE> * </PRE>
*/ */
public class YaCyDefaultServlet extends HttpServlet { public class YaCyDefaultServlet extends HttpServlet {
@ -139,7 +137,6 @@ public class YaCyDefaultServlet extends HttpServlet {
protected ServletContext _servletContext; protected ServletContext _servletContext;
protected boolean _acceptRanges = true; protected boolean _acceptRanges = true;
protected boolean _dirAllowed = true; protected boolean _dirAllowed = true;
protected boolean _pathInfoOnly = false;
protected Resource _resourceBase; protected Resource _resourceBase;
protected MimeTypes _mimeTypes; protected MimeTypes _mimeTypes;
protected String[] _welcomes; protected String[] _welcomes;
@ -172,7 +169,6 @@ public class YaCyDefaultServlet extends HttpServlet {
} }
_acceptRanges = getInitBoolean("acceptRanges", _acceptRanges); _acceptRanges = getInitBoolean("acceptRanges", _acceptRanges);
_dirAllowed = getInitBoolean("dirAllowed", _dirAllowed); _dirAllowed = getInitBoolean("dirAllowed", _dirAllowed);
_pathInfoOnly = getInitBoolean("pathInfoOnly", _pathInfoOnly);
Resource.setDefaultUseCaches(false); // caching is handled internally (prevent double caching) Resource.setDefaultUseCaches(false); // caching is handled internally (prevent double caching)
@ -245,19 +241,15 @@ public class YaCyDefaultServlet extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
String servletPath;
String pathInfo; String pathInfo;
Enumeration<String> reqRanges = null; Enumeration<String> reqRanges = null;
boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null; boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;
if (included) { if (included) {
servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
if (servletPath == null) { if (pathInfo == null) {
servletPath = request.getServletPath();
pathInfo = request.getPathInfo(); pathInfo = request.getPathInfo();
} }
} else { } else {
servletPath = _pathInfoOnly ? "/" : request.getServletPath();
pathInfo = request.getPathInfo(); pathInfo = request.getPathInfo();
// Is this a Range request? // Is this a Range request?
@ -267,8 +259,8 @@ public class YaCyDefaultServlet extends HttpServlet {
} }
} }
String pathInContext = URIUtil.addPaths(servletPath, pathInfo); String pathInContext = pathInfo == null ? "/" : pathInfo; // this is the path of the resource in _resourceBase (= path within htroot respective htDocs)
boolean endsWithSlash = (pathInfo == null ? request.getServletPath() : pathInfo).endsWith(URIUtil.SLASH); boolean endsWithSlash = pathInContext.endsWith(URIUtil.SLASH);
// Find the resource // Find the resource
Resource resource = null; Resource resource = null;

Loading…
Cancel
Save