Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -36,6 +36,7 @@ public void handle(HttpExchange exchange) {

if (route == null) {
var ctx = new JdkContext(mgr, exchange, uri, Set.of());
ctx.setMode(Mode.EXCHANGE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move this into the constructor. Will merge this in but look to adjust later.

mgr.handleException(
ctx,
new NotFoundException(
Expand Down
18 changes: 14 additions & 4 deletions avaje-jex/src/test/java/io/avaje/jex/core/RedirectTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.avaje.jex.core;

import io.avaje.jex.Jex;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

import java.net.http.HttpResponse;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

import io.avaje.jex.Jex;
import io.avaje.jex.http.NotFoundException;

class RedirectTest {

Expand All @@ -26,6 +28,7 @@ static TestPair init() {
.get("/one", ctx -> ctx.text("one"))
.get("/two", ctx -> ctx.text("two"))
.get("/redirect/me", ctx -> ctx.redirect("/one?from=handler"))
.error(NotFoundException.class, (ctx, e) -> ctx.redirect("/one?from=error"))
.get("/other/me", ctx -> ctx.text("never hit")));
return TestPair.create(app);
}
Expand All @@ -42,6 +45,13 @@ void redirect_via_handler() {
assertThat(res.statusCode()).isEqualTo(200);
}

@Test
void redirect_via_error_handler() {
HttpResponse<String> res = pair.request().path("redirect/error").GET().asString();
assertThat(res.body()).isEqualTo("one");
assertThat(res.statusCode()).isEqualTo(200);
}

@Test
void redirect_via_beforeHandler() {
HttpResponse<String> res = pair.request().path("other/me").GET().asString();
Expand Down