Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Not A Bug
-
Affects Version/s: 6.1.6
-
Fix Version/s: None
-
Component/s: HTTP
-
Labels:None
-
Number of attachments :
Description
I am trying to write a http server which can handle multiple request depending on the port and uri the listeners are listening on.
I add 2 contextHandlers to listen on port 80 and context path's
/test and /test/123
ContextHandler context1 = new ContextHandler();
context1.setContextPath("/test/123");
context1.setAllowNullPathInfo(true);
Handler handler1=new HelloHandler1();
context1.setHandler(handler1);
ContextHandler context0 = new ContextHandler();
context0.setContextPath("/test");
context0.setAllowNullPathInfo(true);
Handler handler0=new HelloHandler();
context0.setHandler(handler0);
Now if the context handler /test/123 is added first followed by context handler /test the request are forwarded in correct manner cause jetty takes out handlers from collection one by one and use this code to compare the context path:
// Nope - so check the target.
if (dispatch==REQUEST)
{
if (target.equals(_contextPath))
{
if (!_allowNullPathInfo && !target.endsWith(URIUtil.SLASH))
if (_contextPath.length()>1)
{ target=URIUtil.SLASH; request.setAttribute("org.mortbay.jetty.nullPathInfo",target); } }
else if (target.startsWith(_contextPath) && (_contextPath.length()==1 || target.charAt(_contextPath.length())=='/'))
else
{ // Not for this context! return; } }
}
But if /test context handler is added before the /test/123 than requests belonging to /test/123 are also dispatched to /test context handler due to the fact that
if (target.equals(_contextPath)) return false but if (target.startsWith(_contextPath) && (_contextPath.length()==1 || target.charAt(_contextPath.length())=='/')) returns true.
This is not the right behavior as order of adding handlers decide to which handler the request will be dispatched rather than the corrcet context path.
Can you please tell me if there is any work around for this or if this can be fixed.
Just to summarize:
Context handlers registered :
/test
/test/123
Request sent to http://host:port/test is forwarded to /test
Request sent to http://host:port/test/123 is forwarded to /test---Incorrect behavior
Context handlers registered :
/test/123
/test
Request sent to http://host:port/test is forwarded to /test
Request sent to http://host:port/test/123 is forwarded to /test/123
First case should also work fine and there should be an option so that only absolute context paths are compared and not the startsWith api.
"Can you please tell me if there is any work around for this or if this can be fixed."
As a temporary workaround ...you said it yourself... add the /test/123 context first before /test ...
Its a matter of configuring it properly. (shouldn't be too hard)
We'll definitely take a look at this and tweak the code if its reasonable (performance wise).