Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ static StaticResourceHandlerBuilder builder(String root) {

@Override
public void apply(Jex jex) {

path =
Objects.requireNonNull(path)
.transform(s -> path.endsWith("/") && directoryIndex != null ? path + "*" : path);

jex.get(path, createHandler(jex.config().compression()), roles);
}

Expand All @@ -52,8 +57,7 @@ public StaticContent build() {

ExchangeHandler createHandler(CompressionConfig compress) {
path =
Objects.requireNonNull(path)
.transform(this::prependSlash)
path.transform(this::prependSlash)
.transform(s -> s.endsWith("/*") ? s.substring(0, s.length() - 2) : s);

root = isClasspath ? root.transform(this::prependSlash) : root;
Expand All @@ -76,7 +80,7 @@ ExchangeHandler createHandler(CompressionConfig compress) {

@Override
public StaticResourceHandlerBuilder route(String path, Role... roles) {
this.path = path.endsWith("/") ? path + "*" : path;
this.path = path;
this.roles = roles;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ static TestPair init() {
.plugin(defaultFile().route("/indexWildFile/*").build())
.plugin(defaultCP().route("/sus/").build())
.plugin(defaultFile().route("/susFile/*").build())
.plugin(StaticContent.ofClassPath("/logback.xml").route("/single").build())
.plugin(StaticContent.ofClassPath("/logback.xml").route("/").build())
.plugin(
StaticContent.ofFile("src/test/resources/logback.xml")
.route("/singleFile").build());
.route("/singleFile")
.build());

return TestPair.create(app);
}
Expand Down Expand Up @@ -90,12 +91,18 @@ void getDirContentCP() {

@Test
void getSingleFileCP() {
pair.request().path("single").GET().asString();
HttpResponse<String> res = pair.request().path("single").GET().asString();
pair.request().GET().asString();
HttpResponse<String> res = pair.request().GET().asString();
assertThat(res.statusCode()).isEqualTo(200);
assertThat(res.headers().firstValue("Content-Type").orElseThrow()).contains("xml");
}

@Test
void get404() {
HttpResponse<String> res = pair.request().path("unknown").path("index.html").GET().asString();
assertThat(res.statusCode()).isEqualTo(404);
}

@Test
void getIndexFile() {
pair.request().path("indexFile").GET().asString();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<maven.compiler.proc>full</maven.compiler.proc>
<avaje.config.version>4.0</avaje.config.version>
<avaje.inject.version>11.3</avaje.inject.version>
<avaje.jsonb.version>3.1</avaje.jsonb.version>
<avaje.jsonb.version>3.2</avaje.jsonb.version>
<avaje.http.version>3.1</avaje.http.version>
<avaje.metrics.version>9.4</avaje.metrics.version>
<avaje.validator.version>2.9</avaje.validator.version>
Expand Down