-
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?
Changes from all commits
6966d73
946070f
b373bd3
4c512a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,11 @@ | |
import java.util.Objects; | ||
|
||
import org.eclipse.jetty.http.pathmap.MappedResource; | ||
import org.eclipse.jetty.http.pathmap.MatchedPath; | ||
import org.eclipse.jetty.http.pathmap.MatchedResource; | ||
import org.eclipse.jetty.http.pathmap.PathMappings; | ||
import org.eclipse.jetty.http.pathmap.PathSpec; | ||
import org.eclipse.jetty.server.Context; | ||
import org.eclipse.jetty.server.Handler; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Response; | ||
|
@@ -111,11 +113,49 @@ public boolean handle(Request request, Response response, Callback callback) thr | |
return false; | ||
} | ||
Handler handler = matchedResource.getResource(); | ||
PathSpec pathSpec = matchedResource.getPathSpec(); | ||
if (LOG.isDebugEnabled()) | ||
LOG.debug("Matched {} to {} -> {}", pathInContext, matchedResource.getPathSpec(), handler); | ||
boolean handled = handler.handle(request, response, callback); | ||
|
||
PathSpecRequest pathSpecRequest = new PathSpecRequest(request, pathSpec); | ||
boolean handled = handler.handle(pathSpecRequest, response, callback); | ||
Comment on lines
+120
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make this optional? Perhaps not all usages will want the context set... specially if the handler mapped is itself a ContextHandler. Or maybe this is in a PathMappingsHandler.Contextual subclass? |
||
if (LOG.isDebugEnabled()) | ||
LOG.debug("Handled {} {} by {}", handled, pathInContext, handler); | ||
return handled; | ||
} | ||
|
||
private static class PathSpecRequest extends Request.Wrapper | ||
{ | ||
private final PathSpec pathSpec; | ||
private final Context context; | ||
private final MatchedPath matchedPath; | ||
|
||
public PathSpecRequest(Request request, PathSpec pathSpec) | ||
{ | ||
super(request); | ||
this.pathSpec = pathSpec; | ||
matchedPath = pathSpec.matched(request.getHttpURI().getCanonicalPath()); | ||
setAttribute(PathSpec.class.getName(), this.pathSpec); | ||
this.context = new Context.Wrapper(request.getContext()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be good to reuse this wrapper for every mapping to the same context. ... but maybe don't do this yet... just keep it in mind whilst we work out the other details. |
||
{ | ||
@Override | ||
public String getContextPath() | ||
{ | ||
return matchedPath.getPathMatch(); | ||
} | ||
|
||
@Override | ||
public String getPathInContext(String canonicallyEncodedPath) | ||
{ | ||
return matchedPath.getPathInfo(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Context getContext() | ||
{ | ||
return context; | ||
} | ||
} | ||
} |
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.
Does the contextualization of a request make sense for non prefix matches? Perhaps this is better in a subclass that only allows prefix patterns?