-
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
Jetty 12 - request.getContext().getContextPath()
should return full context, not just last one
#8749
Comments
Uhm. From the point of view of the last The question is what does And I expect I would expect to receive a |
Using the original setup of
|
This is kind of a very strange setup... but let's go with it. The Perhaps a new method |
Lets not go down this path just yet. |
A related question, If we had a setup of how could |
So I think we can support this without too much expense with the following method on Request: default String getContextPath()
{
Context context = getContext();
return context == null ? null : context.getContextPath();
} which we would implement in Request.Wrapper as: @Override
public String getContextPath()
{
Context context = getContext();
if (context == null)
return null;
Request.Wrapper wrapper = this;
String contextPath = context.getContextPath();
while (wrapper != null)
{
Request wrapped = wrapper.getWrapped();
Context outer = wrapped.getContext();
if (context != outer)
{
if (outer == null || outer instanceof Server.ServerContext)
return contextPath;
contextPath = URIUtil.addPaths(outer.getContextPath(), contextPath);
context = outer;
}
wrapper = wrapped instanceof Request.Wrapper w ? w : null;
}
return contextPath;
} Which for the simple case of a single @Override
public String getContextPath()
{
Context context = getContext();
Request.Wrapper wrapper = this;
String contextPath = context.getContextPath();
Context outer = wrapper.getWrapped().getContext();
return (outer instanceof Server.ServerContext) ? contextPath : null;
} So we could do it. @joakime can you test this with your example? |
Note that we'd need to be explicit in the javadoc about the difference between |
Where do you see that last snippet |
@joakime that last snippet is not really code.... that is what the full impl devolves down to in the common case of a single context. I was trying to demonstrate how it would be rather cheap unless we did have nested contexts. |
Reverted that change... So |
This issue has been automatically marked as stale because it has been a |
Closing as PR #8758 addressed this |
Jetty version(s)
12
Description
The
request.getContext().getContextPath()
only returns the last context seen, not the full context path up to this point.In this scenario, where we have 3
ContextHandler
nested inside of each other, the final Handler only sees the last contextPath.(The assertion fails, as it expected
/a/b/c
but only got/c
)This makes it hard to rewrite / redirect / change the URI without the knowledge of the full context.
(for example, putting a
RewriteHandler
after aContextHandler
)The text was updated successfully, but these errors were encountered: