Request header in Input to an Amazon API Gateway Lambda authorizer transformed in lowercase

293 Views Asked by At

I have an Rest ApiGW with a custom authorizer. Form docs https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html#w37aac15b9c11c26c29b5 the request headers shuold be inserted in the event fired to the authorizer lambda.

I didn't get the reason why sometimes header names are transformed in lowercase and sometimes are not!

I see this in ApiGw log row without lowercase conversion:

Endpoint request body after transformations: 
{""type"":""REQUEST"",
""methodArn"":""arn:aws:execute-api:eu-south-1:634374009822:ybm6x73l0l/unique/POST/attachments"",
""resource"":""/attachments"",
""path"":""/delivery/attachments"",
""httpMethod"":""POST"",
""headers"":
{""Accept"":""application/json"",
""Accept-Encoding"":""gzip, deflate, br"",
""Authorization"":""Bearer xxxxx [TRUNCATED]"

and row with lowercase header names conversion

Endpoint request body after transformations: 
{""type"":""REQUEST"",
""methodArn"":""arn:aws:execute-api:eu-south-1:634374009822:ybm6x73l0l/unique/POST/attachments"",
""resource"":""/attachments"",
""path"":""/delivery/attachments"",
""httpMethod"":""POST"",
""headers"":
{""accept"":""application/json"",
""accept-encoding"":""gzip, deflate, br"",
""authorization"":""Bearer xxxxx [TRUNCATED]"

I know http header should be treat case insensitive, but it should be a reason to this behavoir?

1

There are 1 best solutions below

0
Matteo Turra On

I found this behaviour depends on the http protocol verion. If HTTP/1 is used headers names are not converted to lowercase, instead if HTTP/2 this conversion is used in authorizer event construction.

Now I know and I'll use only lowercase headers. :-D