I understand the use case you explain and why PathHandlers behave like that!
I do have a couple of workarounds in mind to fix the issue on my side... But the
easiest/cleanest
would be if PathHandlers had an option to "remove matching path or not". This
option could be /true/
by default. That way, PathMatchers could also be used to chain handlers that are not
related together.
Julien
On 2016-07-21 21:14, Stuart Douglas wrote:
This is by design, as it allows later handlers to only deal with the
relative path (e.g. if you have files mounted under /files they do not
need to somehow know where they have been mounted, the handler just
deals with the relative path.
It sounds like you want the security handler to use a different type
of handler, maybe something like PredicateHandler (if there is only
one path you care about security wise), or you may want to use
io.undertow.util.PathMatcher to implement your own handler.
Stuart
On Fri, Jul 22, 2016 at 4:06 AM, electrotype <electrotype(a)gmail.com> wrote:
> Hi,
>
> I'm using Undertow 1.2.12.Final (for its Java 7 compatibility).
>
> Let's says I have an exact path "/aaa/bbb" for which I want to chain
two
> handlers managed by two PathHandlers:
>
> - a SecurityInitialHandler
> - a ResourceHandler
>
> In other words, the "/aaa/bbb" exact path is a static resource and is
> protected.
>
> The problem I found is that if the first PathHandler (the one for the
> SecurityInitialHandler) matches, then this code is called, in
> io.undertow.server.handlers.PathHandler#handleRequest(...) :
>
> exchange.setRelativePath(match.getRemaining());
>
> The "/aaa/bbb" path fully matches so the exchange's relativePath is set
to
> "" after that match.
>
> Then, the seconds PathHandler (the one for ResourceHandler) is run. The
> matching is done using:
>
> match = pathMatcher.match(exchange.getRelativePath());
>
> Since the relative path is now "", and not "/aaa/bbb", the
ResourceHandler
> for "/aaa/bbb" is not used, even if it exists.
>
> Worst, since the relative path is now "", the path to match will actually
be
> converted to "/". This is because of
> io.undertow.util.PathMatcher#getExactPath(...) :
>
> return exactPathMatches.get(URLUtils.normalizeSlashes(path));
>
> The normalizeSlashes(path) method convert "" to "/".
>
> This means that the default handler of the second PathHandler will be used
> for "/aaa/bbb". If the "/" static resource exists, it will be
served instead
> of the "/aaa/bbb" resource.
>
> Maybe I'm missing something about PathHandlers though... Any tips?
>
> Thanks!
>
> Julien
>
>
>
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/undertow-dev