Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path parameters #266

Merged
merged 3 commits into from
Nov 2, 2023
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 @@ -54,4 +54,9 @@ public void authedPostWithParams(
public String openGet() {
return "Hello, World!";
}

@Http.Get("/foo/open/echo/{msg}")
public String openEcho(String msg) {
return msg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static void afterAll() {
@Test
void smokeTest() throws IOException, InterruptedException {
assertResponse("http://localhost:8080/foo/open/get", 200, "\"Hello, World!\"");
assertResponse("http://localhost:8080/foo/open/echo/hellother", 200, "\"hellother\"");
}

private void assertResponse(String uri, int statusCode, String expectedResponseText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HeaderValues;
import io.undertow.util.Headers;
import io.undertow.util.PathTemplateMatch;
import java.util.Deque;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -126,7 +128,9 @@ private static void redirect(HttpRedirect redirect, HttpServerExchange exchange)
}

public static Optional<String> pathParameter(String parameter, HttpServerExchange exchange) {
return Optional.ofNullable(exchange.getPathParameters().get(parameter)).map(Deque::getFirst);
Map<String, String> pathParams =
exchange.getAttachment(PathTemplateMatch.ATTACHMENT_KEY).getParameters();
return Optional.ofNullable(pathParams.get(parameter));
}

public static Optional<String> headerParameter(String parameter, HttpServerExchange exchange) {
Expand Down
Loading