Repository navigation
fix(lambda-http): keep every value of a repeated request header - #1184
Open
hoangchunghien wants to merge 1 commit into
Open
hoangchunghien wants to merge 1 commit into
hoangchunghien wants to merge 1 commit into
Conversation
API Gateway REST, ALB and WebSocket events carry a repeated header in both maps: `headers` holds only its last value and `multiValueHeaders` holds all of them. The request conversion extended the multi-value map with the single-value one, and HeaderMap::extend replaces existing keys, so the handler saw only the last value. Merge so that a single-value header is used only when the multi-value map does not already have that name.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A request header that appears more than once reaches the handler with only its last value when the event comes from API Gateway REST (v1), an ALB with multi-value headers enabled, or an API Gateway WebSocket.
These events carry a repeated header in both maps:
headersholds the last value andmultiValueHeadersholds all of them.lambda-http/src/request.rsbuilds the request headers like this:HeaderMap::extendreplaces the values of keys that are already present, so the single-value copy overwrites the complete list. The same two lines appear ininto_proxy_request,into_alb_requestandinto_websocket_request.Fix
A small
merge_headershelper keeps the multi-value entries, and takes a single-value entry only for a name the multi-value map does not have. Events that send only one of the two maps behave exactly as before.Tests
Two fixtures copy the existing multi-value ones and add a header present in both maps (
"X-Repeated": "second"and["first", "second"]). Two tests assert that both values arrive:keeps_every_value_of_a_header_repeated_in_apigw_multi_value_headerskeeps_every_value_of_a_header_repeated_in_alb_multi_value_headersOn
main(7f89224) both fail withleft: ["second"],right: ["first", "second"].(
lambda-integration-testsneedsTEST_ENDPOINTandSECRET_TOKEN, so I did not run it.)I also checked it end to end. I found this through aws-lambda-web-adapter, which uses
lambda_http, running in the Lambda Runtime Interface Emulator in front of an app that echoes its request headers. A REST API event withx-m: 1andx-m: 2reached the app as['2']withlambda_http1.3.0, and as['1', '2']with this branch patched in. The same held for an ALB event.