[keycloak-dev] Trailing slash

Sebastian Laskawiec slaskawi at redhat.com
Wed Feb 20 08:47:59 EST 2019

Hey guys,

I'm working on migrating Jetty adapters to our base testsuite at the moment
and I noticed an interesting problem.

The URLProvider is responsible for adjusting injected URLs into the Page
objects. One of the things it does is trimming the trailing slash out, so
that "http://localhost:8280/client-secret-jwt-secure-portal/" becomes "
http://localhost:8280/client-secret-jwt-secure-portal". We depend on this
functionality a lot in our testsuite when constructing all kind of
assertions that include myPage.getInjectedUrl().toString(). In other words,
if we inject a URL with a trailing slash, there will be quite a lot of test
that fail.

Trailing space at the end is not meaningless unfortunately. It is being
used by the container to find proper context. Here's one of the best
explanations I found so far [1].

Jetty enforces trailing slashes for Servlets deployed in the container. If
you hit a Servlet without a slash (
http://localhost:8280/client-secret-jwt-secure-portal for example), you
will be redirected (with HTTP 302) to a version that has it (
http://localhost:8280/client-secret-jwt-secure-portal/). This of course
breaks some of the tests in our testsuite (since the Resteasy HTTP Engine
doesn't follow redirects by default). It is also worth to mention, that
Arquillian also adds trailing slash at the end of the Servlet context [2].
So by default, it injects all URLs with trailing space.

My take on this is that we should not trim the trailing slash. Moreover, we
should never manipulate a raw string representation of a URL. What we
should do instead is to use URI#resolve method if we need to query
sub-contexts. Using URI instead of URL is extremely important when it comes
to equality (if you're interested more in this, please read [3]).

If you agree with me, I'll go ahead and create a JIRA for it.


See org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet#getBaseURIAsString
[3] http://blog.markfeeney.com/2010/11/java-uri-vs-url.html

More information about the keycloak-dev mailing list