Skip to content
Open
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 @@ -124,16 +124,22 @@ private static HttpServletRequest generateRequest1(String request, Context lambd
populateQueryStringParametersV1(v1Request, httpRequest);
populateMultiValueQueryStringParametersV1(v1Request, httpRequest);

if (v1Request.getMultiValueHeaders() != null) {
final boolean hasSVH = v1Request.getHeaders() != null && !v1Request.getHeaders().isEmpty();
final boolean hasMVH = v1Request.getMultiValueHeaders() != null && !v1Request.getMultiValueHeaders().isEmpty();
if (hasMVH) {
MultiValueMapAdapter headers = new MultiValueMapAdapter(v1Request.getMultiValueHeaders());
httpRequest.setHeaders(headers);
}
populateContentAndContentType(
v1Request.getBody(),
v1Request.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE),
v1Request.isBase64Encoded(),
httpRequest
);
else if (hasSVH)
{
v1Request.getHeaders().forEach(httpRequest::addHeader);
}
populateContentAndContentType(
v1Request.getBody(),
v1Request.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE),
v1Request.isBase64Encoded(),
httpRequest
);
if (v1Request.getRequestContext() != null) {
httpRequest.setAttribute(RequestReader.API_GATEWAY_CONTEXT_PROPERTY, v1Request.getRequestContext());
httpRequest.setAttribute(RequestReader.ALB_CONTEXT_PROPERTY, v1Request.getRequestContext().getElb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,57 @@ public class AwsSpringHttpProcessingUtilsTests {
+ " \"isBase64Encoded\": false\n"
+ "}";

private static String API_GATEWAY_EVENT_WITHOUT_MULTIVALUE_HEADERS = "{\n"
+ " \"version\": \"1.0\",\n"
+ " \"resource\": \"$default\",\n"
+ " \"path\": \"/async\",\n"
+ " \"httpMethod\": \"POST\",\n"
+ " \"headers\": {\n"
+ " \"Content-Length\": \"45\",\n"
+ " \"Content-Type\": \"application/json\",\n"
+ " \"Host\": \"i76bfh111.execute-api.eu-west-3.amazonaws.com\",\n"
+ " \"User-Agent\": \"curl/7.79.1\",\n"
+ " \"X-Amzn-Trace-Id\": \"Root=1-64087690-2151375b219d3ba3389ea84e\",\n"
+ " \"X-Forwarded-For\": \"109.210.252.44\",\n"
+ " \"X-Forwarded-Port\": \"443\",\n"
+ " \"X-Forwarded-Proto\": \"https\",\n"
+ " \"accept\": \"*/*\"\n"
+ " },\n"
+ " \"queryStringParameters\": {\n"
+ " \"abc\": \"xyz\",\n"
+ " \"parameter1\": \"value2\"\n"
+ " },\n"
+ " \"multiValueQueryStringParameters\": {\n"
+ " \"abc\": [\n"
+ " \"xyz\"\n"
+ " ],\n"
+ " \"parameter1\": [\n"
+ " \"value1\",\n"
+ " \"value2\"\n"
+ " ]\n"
+ " },\n"
+ " \"requestContext\": {\n"
+ " \"accountId\": \"123456789098\",\n"
+ " \"apiId\": \"i76bfhczs0\",\n"
+ " \"domainName\": \"i76bfhc111.execute-api.eu-west-3.amazonaws.com\",\n"
+ " \"domainPrefix\": \"i76bfhczs0\",\n"
+ " \"extendedRequestId\": \"Bdd2ngt5iGYEMIg=\",\n"
+ " \"httpMethod\": \"POST\",\n"
+ " \"path\": \"/pets\",\n"
+ " \"protocol\": \"HTTP/1.1\",\n"
+ " \"requestId\": \"Bdd2ngt5iGYEMIg=\",\n"
+ " \"requestTime\": \"08/Mar/2023:11:50:40 +0000\",\n"
+ " \"requestTimeEpoch\": 1678276240455,\n"
+ " \"resourceId\": \"$default\",\n"
+ " \"resourcePath\": \"$default\",\n"
+ " \"stage\": \"$default\"\n"
+ " },\n"
+ " \"pathParameters\": null,\n"
+ " \"stageVariables\": null,\n"
+ " \"body\": \"{\\\"name\\\":\\\"bob\\\"}\",\n"
+ " \"isBase64Encoded\": false\n"
+ "}";

private static String API_GATEWAY_EVENT_V2 = "{\n" +
" \"version\": \"2.0\",\n" +
" \"routeKey\": \"$default\",\n" +
Expand Down Expand Up @@ -215,7 +266,7 @@ public class AwsSpringHttpProcessingUtilsTests {
private final ObjectMapper mapper = new ObjectMapper();

public static Collection<String> data() {
return Arrays.asList(new String[]{API_GATEWAY_EVENT, API_GATEWAY_EVENT_V2, ALB_EVENT});
return Arrays.asList(new String[]{API_GATEWAY_EVENT, API_GATEWAY_EVENT_WITHOUT_MULTIVALUE_HEADERS, API_GATEWAY_EVENT_V2, ALB_EVENT});
}

@MethodSource("data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,81 @@ public class SpringDelegatingLambdaContainerHandlerTests {
+ " \"isBase64Encoded\": false\n"
+ "}";

/**
* NOTE: while API Gateway typically sets multiValueHeaders, even if they are only a copy of the single value
* headers, this is NOT the case when an API is invoked from the AWS console. In this situation, there are NO
* multivalue headers.
*/
private static String API_GATEWAY_EVENT_WITHOUT_MULTIVALUE_HEADERS = "{\n"
+ " \"version\": \"1.0\",\n"
+ " \"resource\": \"$default\",\n"
+ " \"path\": \"/async\",\n"
+ " \"httpMethod\": \"POST\",\n"
+ " \"headers\": {\n"
+ " \"Content-Length\": \"45\",\n"
+ " \"Content-Type\": \"application/json\",\n"
+ " \"Host\": \"i76bfh111.execute-api.eu-west-3.amazonaws.com\",\n"
+ " \"User-Agent\": \"curl/7.79.1\",\n"
+ " \"X-Amzn-Trace-Id\": \"Root=1-64087690-2151375b219d3ba3389ea84e\",\n"
+ " \"X-Forwarded-For\": \"109.210.252.44\",\n"
+ " \"X-Forwarded-Port\": \"443\",\n"
+ " \"X-Forwarded-Proto\": \"https\",\n"
+ " \"accept\": \"*/*\"\n"
+ " },\n"
+ " \"queryStringParameters\": {\n"
+ " \"abc\": \"xyz\",\n"
+ " \"name\": \"Ricky\",\n"
+ " \"foo\": \"baz\"\n"
+ " },\n"
+ " \"multiValueQueryStringParameters\": {\n"
+ " \"abc\": [\n"
+ " \"xyz\"\n"
+ " ],\n"
+ " \"name\": [\n"
+ " \"Ricky\"\n"
+ " ],\n"
+ " \"foo\": [\n"
+ " \"bar\",\n"
+ " \"baz\"\n"
+ " ]\n"
+ " },\n"
+ " \"requestContext\": {\n"
+ " \"accountId\": \"123456789098\",\n"
+ " \"apiId\": \"i76bfhczs0\",\n"
+ " \"domainName\": \"i76bfhc111.execute-api.eu-west-3.amazonaws.com\",\n"
+ " \"domainPrefix\": \"i76bfhczs0\",\n"
+ " \"extendedRequestId\": \"Bdd2ngt5iGYEMIg=\",\n"
+ " \"httpMethod\": \"POST\",\n"
+ " \"identity\": {\n"
+ " \"accessKey\": null,\n"
+ " \"accountId\": null,\n"
+ " \"caller\": null,\n"
+ " \"cognitoAmr\": null,\n"
+ " \"cognitoAuthenticationProvider\": null,\n"
+ " \"cognitoAuthenticationType\": null,\n"
+ " \"cognitoIdentityId\": null,\n"
+ " \"cognitoIdentityPoolId\": null,\n"
+ " \"principalOrgId\": null,\n"
+ " \"sourceIp\": \"109.210.252.44\",\n"
+ " \"user\": null,\n"
+ " \"userAgent\": \"curl/7.79.1\",\n"
+ " \"userArn\": null\n"
+ " },\n"
+ " \"path\": \"/pets\",\n"
+ " \"protocol\": \"HTTP/1.1\",\n"
+ " \"requestId\": \"Bdd2ngt5iGYEMIg=\",\n"
+ " \"requestTime\": \"08/Mar/2023:11:50:40 +0000\",\n"
+ " \"requestTimeEpoch\": 1678276240455,\n"
+ " \"resourceId\": \"$default\",\n"
+ " \"resourcePath\": \"$default\",\n"
+ " \"stage\": \"$default\"\n"
+ " },\n"
+ " \"pathParameters\": null,\n"
+ " \"stageVariables\": null,\n"
+ " \"body\": \"{\\\"name\\\":\\\"bob\\\"}\",\n"
+ " \"isBase64Encoded\": false\n"
+ "}";

private static String API_GATEWAY_EVENT_V2 = "{\n" +
" \"version\": \"2.0\",\n" +
" \"routeKey\": \"$default\",\n" +
Expand Down Expand Up @@ -202,7 +277,7 @@ public void initServletAppTest() throws ContainerInitializationException {
}

public static Collection<String> data() {
return Arrays.asList(new String[]{API_GATEWAY_EVENT, API_GATEWAY_EVENT_V2});
return Arrays.asList(new String[]{API_GATEWAY_EVENT, API_GATEWAY_EVENT_WITHOUT_MULTIVALUE_HEADERS, API_GATEWAY_EVENT_V2});
}

@MethodSource("data")
Expand Down