-
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 #11494 - PathMappingsHandler exposes PathSpec and Context based on PathSpec. #11497
base: jetty-12.0.x
Are you sure you want to change the base?
Conversation
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 like the direction this is going.... but a few niggles/questions....
I'd also like to consider the option of setting the contexts base resource with the mapping... as then all the mappings could be to the same ResourceHandler and it would just use the context to find the mapping!
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Show resolved
Hide resolved
public String getPathInContext(String canonicallyEncodedPath) | ||
{ | ||
MatchedPath matchedPath = pathSpec.matched(canonicallyEncodedPath); | ||
return matchedPath.getPathInfo(); | ||
} |
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 this is correct. I think you can just use the default method.
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Show resolved
Hide resolved
@joakime maybe implement it like:
So it ends up being a convenience class that wraps passed handlers with our existing |
@joakime thoughts? |
The truth of the context-path (and path info) is from the PathSpec, and while we have our own, and can make some good guesses on how it should behave, we are also making those assumptions based on what we experience. We shouldn't assume that the pathInfo is always what's left over from the context-path. What if someone has the following RegexPathSpec ? pathMappingsHandler.addMapping(new RegexPathSpec("^/rest/(?<name>.*)/ver-[0-9]+/(?<info>.*)$"), new ContextDumpHandler()); That will return on the input path
I added this example to the testcases in this PR. |
I think that breaks a fundamental invariant that we have (and probably should better document): If we do not respect these invariants, then things will break. So we cannot use RegEx matching to determine a contextPath unless it is in the PREFIX group and meets the invariant. |
…th-mappings-handler-context
…th-mappings-handler-context
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Show resolved
Hide resolved
I've tagged this for 12.1.x. Please rebase. |
@Override | ||
public String getPathInContext(String canonicallyEncodedPath) | ||
{ | ||
return matchedPath.getPathInfo(); |
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.
Hmmm I'm not sure we can just return that pathInfo. I think we have to do:
return matchedPath.getPathInfo(); | |
return Context.getPathInContext(getWrapped().getContext().getContextPath(), canonicallyEncodedPath); |
rebase against 12.1.x |
Fixes: #11494