-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #5025 - wrong welcome file handling with dispatcher.include() a… #5026
Conversation
c7d114f
to
72d3d1d
Compare
HttpTester.Response response; | ||
|
||
// Test included alt default | ||
rawResponse = connector.getResponse("GET /context/gateway HTTP/1.0\r\n\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be GET /context/gateway/ HTTP/1.0\r\n\r\n
as you are requesting content belonging to the url-pattern of /gateway/*
which the request to /gateway
will not match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked org.eclipse.jetty.http.pathmap.PathMappings#getMatch()
and /p
request is successfully matched for servlet mapped to /p/*
- it's kept in org.eclipse.jetty.http.pathmap.PathMappings#_prefixMap
:
_prefixMap = {org.eclipse.jetty.util.ArrayTernaryTrie@2636} "{/p=MappedResource[pathSpec=ServletPathSpec["/p/*",pathDepth=2,group=PREFIX_GLOB],resource=default-servlet@2c16bab9==org.ops4j.pax.web.service.jetty.internal.EmbeddedJettyTest$11,jsp=null,order=-1,inst=true,async=true]}"
LO: int = 1 (0x1)
EQ: int = 2 (0x2)
HI: int = 3 (0x3)
ROW_SIZE: int = 4 (0x4)
_tree: char[] = {char[512]@2893}
_key: java.lang.String[] = {java.lang.String[128]@2894}
2 = "/p"
_value: java.lang.Object[] = {java.lang.Object[128]@2895}
2 = {org.eclipse.jetty.http.pathmap.MappedResource@2643} "MappedResource[pathSpec=ServletPathSpec["/p/*",pathDepth=2,group=PREFIX_GLOB],resource=default-servlet@2c16bab9==org.ops4j.pax.web.service.jetty.internal.EmbeddedJettyTest$11,jsp=null,order=-1,inst=true,async=true]"
pathSpec: org.eclipse.jetty.http.pathmap.PathSpec = {org.eclipse.jetty.http.pathmap.ServletPathSpec@2897} "ServletPathSpec["/p/*",pathDepth=2,group=PREFIX_GLOB]"
resource: java.lang.Object = {org.eclipse.jetty.servlet.ServletHolder@2656} "default-servlet@2c16bab9==org.ops4j.pax.web.service.jetty.internal.EmbeddedJettyTest$11,jsp=null,order=-1,inst=true,async=true"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've got 2 differents tests to do here:
-
url is /context/gateway WITHOUT the trailing slash, which will go to line 377 of ResourceService that does a 302 redirect to url that adds the trailing slash
-
url is /context/gateway/ WITH the trailing slash, which will go to the code at line 402 of ResourceService
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grgrzybek I'd still like to see one request with GET /context/gateway
and one with GET /context/gateway/
, because the first one will do a redirect before doing the new include path handling: I just want to ensure that we've exercised both codepaths.
72d3d1d
to
a14a665
Compare
req.getRequestDispatcher("/alt/").include(req, resp); | ||
} | ||
}); | ||
context.addServlet(gwholder, "/gateway/*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addServlet should be done before Server.start()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's the case in other tests inside org.eclipse.jetty.servlet.DefaultServletTest
...
FS.ensureDirExists(altRoot); | ||
Path altIndex = altRoot.resolve("index.html"); | ||
|
||
ServletHolder defholder = context.addServlet(DefaultServlet.class, "/alt/*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addServlet should be done before Server.start()
I'll let others look at this too, but I feel this should be done against branch |
I'm not sure about the branch. I'm mostly interested in version 9.4.x, but I see that 10.x is the "current" version being developed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can get rid of the unnecessary "if" statement, and make 2 tests instead of 1, we're golden.
@@ -401,8 +401,13 @@ protected void sendWelcome(HttpContent content, String pathInContext, boolean en | |||
|
|||
if (welcome != null) | |||
{ | |||
String servletPath = included ? (String)request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH) | |||
: request.getServletPath(); | |||
if (servletPath == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good solution. I would delete the extra "if" at line 406 because that can never happen, unless there's a bug in jetty :)
HttpTester.Response response; | ||
|
||
// Test included alt default | ||
rawResponse = connector.getResponse("GET /context/gateway HTTP/1.0\r\n\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've got 2 differents tests to do here:
-
url is /context/gateway WITHOUT the trailing slash, which will go to line 377 of ResourceService that does a 302 redirect to url that adds the trailing slash
-
url is /context/gateway/ WITH the trailing slash, which will go to the code at line 402 of ResourceService
a14a665
to
8439595
Compare
…e() and non-default mapping Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
8439595
to
93fa21b
Compare
I've just removed the extra |
HttpTester.Response response; | ||
|
||
// Test included alt default | ||
rawResponse = connector.getResponse("GET /context/gateway HTTP/1.0\r\n\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grgrzybek I'd still like to see one request with GET /context/gateway
and one with GET /context/gateway/
, because the first one will do a redirect before doing the new include path handling: I just want to ensure that we've exercised both codepaths.
I've changed the mapping of the gateway servlet from prefix mapping to strict mapping (from My point with this test was to check how |
When I checked: context.addServlet(gwholder, "/gateway/*"); again, according to my expectations (and Servlet specification), all these requests:
are mapped to gateway servlet without redirect and the servlet invokes dispatcher with include for req.getRequestDispatcher("/alt/").include(req, resp); :) |
@grgrzybek oh, I think we're talking about different things. I was wanting to check the behaviour at line 377 of ResourceService (which sends a redirect if the request didn't end in '/'). But, as I've confirmed via a test, the redirect wouldn't work from an include anyway, as include is not permitted to mess with the response headers. So, to sum up: we're good! Thanks for the PR. |
Thanks @janbartel for review! yes - I went through include + redirect attempts myself in pax-web 8 ;) |
@janbartel May I kindly ask for a backport to Jetty 9.4.x too? |
…nd non-default mapping (#5026) Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com> Signed-off-by: Jan Bartel <janb@webtide.com>
@grgrzybek I knew you were going to ask me to do that :). Done, cherrypicked back to 9.4.x branch just now. |
Ha :) Thanks - much appreciated! |
By the way - I don't have test yet, but when checking Jetty / Tomcat / Undertow, I saw that Jetty sets wrong value to |
@grgrzybek opened issue #5057 about that |
…nd non-default mapping