awslabs / aws-lambda-rust-runtime

A Rust runtime for AWS Lambda
Apache License 2.0
3.29k stars 335 forks source link

fix: return correct header keys for each integration #877

Closed fluxth closed 3 months ago

fluxth commented 3 months ago

Description of changes

Fixes #871 Fixes #876

Each integration handle header keys differently, this patch tries to address these differences so that we have proper headers in responses.

Note: I don't currently have time to spin up all these integrations on AWS to test this, so this patch is entirely based on documentation and reference code from awslabs/aws-lambda-go-api-proxy repo. Please feel free to test and leave feedback in the reviews.

References

ALB Integration https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers-response

The names of the fields used for headers differ depending on whether you enable multi-value headers for the target group. You must use multiValueHeaders if you have enabled multi-value headers and headers otherwise.

APIGW v1 Integration https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format

If you specify values for both headers and multiValueHeaders, API Gateway merges them into a single list. If the same key-value pair is specified in both, only the values from multiValueHeaders will appear in the merged list.

APIGW v2 Integration https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html

Format 2.0 doesn't have multiValueHeaders or multiValueQueryStringParameters fields. Duplicate headers are combined with commas and included in the headers field. Duplicate query strings are combined with commas and included in the queryStringParameters field.

awslabs/aws-lambda-go-api-proxy source code

By submitting this pull request

calavera commented 3 months ago

Thanks a lot for diving deep in this issue!