Skip to content

Commit

Permalink
Addressed bug with Spark requests to the root resource not being rout…
Browse files Browse the repository at this point in the history
…ed correctly (#151)
  • Loading branch information
sapessi committed Jun 18, 2018
1 parent 38d0154 commit f18176f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,16 @@ private Map<String, Part> getMultipartFormParametersMap() {


private String cleanUri(String uri) {
String finalUri = (uri == null ? "" : uri);
String finalUri = (uri == null ? "/" : uri);
if (finalUri.equals("/")) {
return finalUri;
}

if (!finalUri.startsWith("/")) {
finalUri = "/" + finalUri;
}

if (finalUri.endsWith(("/"))) {
if (finalUri.endsWith("/")) {
finalUri = finalUri.substring(0, finalUri.length() - 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,24 @@ public void multiCookie_setCookieOnResponse_singleHeaderWithMultipleValues() {
assertTrue(response.getHeaders().get(HttpHeaders.SET_COOKIE).contains(COOKIE_PATH));
}

@Test
public void rootResource_basicRequest_expectSuccess() {
AwsProxyRequest req = new AwsProxyRequestBuilder().method("GET").path("/").build();
AwsProxyResponse response = handler.proxy(req, new MockLambdaContext());

assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().containsKey(CUSTOM_HEADER_KEY));
assertEquals(CUSTOM_HEADER_VALUE, response.getHeaders().get(CUSTOM_HEADER_KEY));
assertEquals(BODY_TEXT_RESPONSE, response.getBody());
}

private static void configureRoutes() {
get("/", (req, res) -> {
res.status(200);
res.header(CUSTOM_HEADER_KEY, CUSTOM_HEADER_VALUE);
return BODY_TEXT_RESPONSE;
});

get("/hello", (req, res) -> {
res.status(200);
res.header(CUSTOM_HEADER_KEY, CUSTOM_HEADER_VALUE);
Expand Down

0 comments on commit f18176f

Please sign in to comment.