-
Notifications
You must be signed in to change notification settings - Fork 565
Response headers not working in HttpAPI PayloadFormat V2 #377
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
Comments
Hi @lbeuster - are you referring to the response headers? Our HTTP API request object does not have a multivalue headers field. |
Yes, the response headers. |
I just checked with the API Gateway team. This is the answer:
We'll mark this as a bug and address it with the next release |
As a workaround, I created an anonymous ResponseWriter instance that concatenates the values in multiHeaderValues with their corresponding header value, if one exists. Here's how I build my lambda handler: handler = new SpringBootProxyHandlerBuilder<HttpApiV2ProxyRequest>()
.springBootApplication(Blah.class)
.defaultHttpApiV2Proxy()
.responseWriter(
new AwsProxyHttpServletResponseWriter() {
@Override
public AwsProxyResponse writeResponse(AwsHttpServletResponse containerResponse,
Context lambdaContext) throws InvalidResponseObjectException {
final AwsProxyResponse awsProxyResponse = super
.writeResponse(containerResponse, lambdaContext);
final Headers multiValueHeaders = awsProxyResponse.getMultiValueHeaders();
if (multiValueHeaders != null) {
Map<String, String> headers;
if (awsProxyResponse.getHeaders() == null) {
headers = new HashMap<>();
} else {
headers = awsProxyResponse.getHeaders();
}
multiValueHeaders.entrySet().forEach(entry -> {
headers.compute(entry.getKey(), (key, existingValue) ->
{
final String commaDelimitedMultiValueHeader = String
.join(",", entry.getValue());
return existingValue != null && !existingValue.isBlank()
? (existingValue + "," + commaDelimitedMultiValueHeader)
: commaDelimitedMultiValueHeader;
});
});
awsProxyResponse.setMultiValueHeaders(null);
awsProxyResponse.setHeaders(headers);
}
return awsProxyResponse;
}
}
)
.buildAndInitialize(); |
Thanks, but payload format version 1.0 is also a good workaround for the moment ;) |
Parametrized the use of the single value headers for the response writer to support the v2 proxy schema for HTTP API
Changed default httpApiV2 constructor for the handler in all the framework implementations
* fix: Use single value headers for HTTP API response (#377) Parametrized the use of the single value headers for the response writer to support the v2 proxy schema for HTTP API * fix: Updated HTTP API handler constructor (#377) Changed default httpApiV2 constructor for the handler in all the framework implementations * fix: Switched to non-mime encoder for respponse (#339)
1.5.2 has now hit maven central. Closing this issue. |
Parametrized the use of the single value headers for the response writer to support the v2 proxy schema for HTTP API
Currently it seems that the serverless container doesn't really support HttpApi with PayloadFormat V2 (with is the default in HttpApi). All headers (even with V2ProxyHandler) are written into the multiheader field but multiheaders are not supported anymore in V2: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
I could reproduce this with a simple spring-boot2 lambda. And also with a simple non-serverless container lambda using the aws-lambda-java-events:APIGatewayV2HTTPResponse class (which still contains the multiheader field). Headers written to the header field were exposed, multiheaders not.
Best regards
Lars
The text was updated successfully, but these errors were encountered: