Skip to content

Commit

Permalink
Fix Jetty with multiple static resources
Browse files Browse the repository at this point in the history
Currently Jetty responds with a 404 if there are multiple static-resources.

I believe we need a Default servlet PER resource, and not a single one trying to handle it all.
  • Loading branch information
timyates committed Aug 24, 2023
1 parent 223b44e commit b8edf21
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,41 @@ class JettyStaticResourceResolutionSpec extends Specification implements TestPro
embeddedServer?.stop()
embeddedServer?.close()
}

void "test resources with multiple nested mapping automatically resolves index.html"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [
'micronaut.router.static-resources.nest-test.paths': ['classpath:nest-test'],
'micronaut.router.static-resources.nest-test.mapping': '/nest-test/**',
'micronaut.router.static-resources.nest.paths': ['classpath:nest-test/nested'],
'micronaut.router.static-resources.nest.mapping': '/nest/**'
])
def client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()).toBlocking()

when:
def nestTestResponse = client.exchange(HttpRequest.GET("/nest-test"), String)
def nestTestText = JettyStaticResourceResolutionSpec.classLoader.getResource("nest-test/index.html").text

def nestResponse = client.exchange(HttpRequest.GET("/nest"), String)
def nestText = JettyStaticResourceResolutionSpec.classLoader.getResource("nest-test/nested/index.html").text

then:
with(nestTestResponse) {
code() == HttpStatus.OK.code
header(CONTENT_TYPE) == "text/html"
Integer.parseInt(header(CONTENT_LENGTH)) > 0
body() == nestTestText
}

with(nestResponse) {
code() == HttpStatus.OK.code
header(CONTENT_TYPE) == "text/html"
Integer.parseInt(header(CONTENT_LENGTH)) > 0
body() == nestText
}

cleanup:
embeddedServer.stop()
embeddedServer.close()
}
}
1 change: 1 addition & 0 deletions http-server-jetty/src/test/resources/nest-test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body><h1>Test</h1></body></html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>Nest</h1>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,41 @@ class TomcatStaticResourceResolutionSpec extends Specification implements TestPr
embeddedServer?.stop()
embeddedServer?.close()
}

void "test resources with multiple nested mapping automatically resolves index.html"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [
'micronaut.router.static-resources.nest-test.paths': ['classpath:nest-test'],
'micronaut.router.static-resources.nest-test.mapping': '/nest-test/**',
'micronaut.router.static-resources.nest.paths': ['classpath:nest-test/nested'],
'micronaut.router.static-resources.nest.mapping': '/nest/**'
])
def client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()).toBlocking()

when:
def nestTestResponse = client.exchange(HttpRequest.GET("/nest-test"), String)
def nestTestText = TomcatStaticResourceResolutionSpec.classLoader.getResource("nest-test/index.html").text

def nestResponse = client.exchange(HttpRequest.GET("/nest"), String)
def nestText = TomcatStaticResourceResolutionSpec.classLoader.getResource("nest-test/nested/index.html").text

then:
with(nestTestResponse) {
code() == HttpStatus.OK.code
header(CONTENT_TYPE) == "text/html"
Integer.parseInt(header(CONTENT_LENGTH)) > 0
body() == nestTestText
}

with(nestResponse) {
code() == HttpStatus.OK.code
header(CONTENT_TYPE) == "text/html"
Integer.parseInt(header(CONTENT_LENGTH)) > 0
body() == nestText
}

cleanup:
embeddedServer.stop()
embeddedServer.close()
}
}
1 change: 1 addition & 0 deletions http-server-tomcat/src/test/resources/nest-test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body><h1>Test</h1></body></html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>Nest</h1>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,41 @@ class UndertowStaticResourceResolutionSpec extends Specification implements Test
embeddedServer?.stop()
embeddedServer?.close()
}

void "test resources with multiple nested mapping automatically resolves index.html"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [
'micronaut.router.static-resources.nest-test.paths': ['classpath:nest-test'],
'micronaut.router.static-resources.nest-test.mapping': '/nest-test/**',
'micronaut.router.static-resources.nest.paths': ['classpath:nest-test/nested'],
'micronaut.router.static-resources.nest.mapping': '/nest/**'
])
def client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()).toBlocking()

when:
def nestTestResponse = client.exchange(HttpRequest.GET("/nest-test"), String)
def nestTestText = UndertowStaticResourceResolutionSpec.classLoader.getResource("nest-test/index.html").text

def nestResponse = client.exchange(HttpRequest.GET("/nest"), String)
def nestText = UndertowStaticResourceResolutionSpec.classLoader.getResource("nest-test/nested/index.html").text

then:
with(nestTestResponse) {
code() == HttpStatus.OK.code
header(CONTENT_TYPE) == "text/html"
Integer.parseInt(header(CONTENT_LENGTH)) > 0
body() == nestTestText
}

with(nestResponse) {
code() == HttpStatus.OK.code
header(CONTENT_TYPE) == "text/html"
Integer.parseInt(header(CONTENT_LENGTH)) > 0
body() == nestText
}

cleanup:
embeddedServer.stop()
embeddedServer.close()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body><h1>Test</h1></body></html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>Nest</h1>
</body>
</html>

0 comments on commit b8edf21

Please sign in to comment.