Skip to content

Commit

Permalink
Fix path parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
a10y committed Nov 1, 2023
1 parent 59a89ef commit bcd595c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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,10 @@
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 +129,8 @@ 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

0 comments on commit bcd595c

Please sign in to comment.