Directory with `index.html` should serve welcome file without redirect
See original GitHub issueActual behavior (the bug)
When you request a directory path /path/foo
and a welcome file exists /path/foo/index.html
, the response is a 302
redirect to /path/foo/
.
Expected behavior
The expectation is that the browser keeps /path/foo
and serves the content of /path/foo/index.html
.
To Reproduce In this unit test:
Disabling the http test client’s handling of redirects will demonstrate this. E.g.:
@Test
fun `normal javalin ignores static directory slashes`() = TestUtil.test(normalJavalin) { _, http ->
http.disableUnirestRedirects()
assertThat(http.getBody("/subpage")).isEqualTo("TEST") // <-- this will fail now since a 302 is returned
assertThat(http.getBody("/subpage/")).isEqualTo("TEST")
}
Additional context
- In our use case we are using vite (with svelte) which generate static files for a portion of our site, and vite’s output is organized with one page per directory, with an
index.html
being the entry point for each page. An additional Javalin static file handler is configured to serve that all that content. - One might argue this is merely an aesthetic issue between showing
/path/foo
vs/path/foo/
in the browser bar. I place a high value on such aesthetics for our users. 😄 - This is relevant only for static content, and I think #1002 may have aimed to fix this, but not sure. Maybe that PR was just to accomplish serving the
index.html
content, even if it meant doing an intermediate redirect. @AlexGustafsson do your/path/foo
urls get redirected to/path/foo/
after your PR? - We are still using newest Javalin 3.x.x for the foreseeable future. @tipsy Are you still accepting PRs for the 3.x.x line? If I get that working, I could look doing at another PR for 4.x.x.
This seems to be fixable – I have pinpointed where Jetty makes the decision to do a redirect vs send back the welcome file. It comes down to how Jetty uses a PathResource
with or without a trailing slash. So that’s a first step toward knowing what to pass into the Jetty function(s) to get the desired behavior. Here’s where Jetty makes its choice:
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
On a good trajectory now I think with a
RewriteHandler
and parsing themanifest.json
that vite produces to know the endpoints. Sorry for the “noise”. 😄Whoops! I got confused by some tags I was looking at! I see the
javalin-3x
branch. I’m at the end of my day – I’ll probably send something tomorrow.