brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.09k stars 367 forks source link

Stop truncating multi-value headers #1691

Closed timkelty closed 7 months ago

timkelty commented 9 months ago

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

As API Gateway 2.0 doesn't support multiValueHeaders – Bref takes only the last value.

It seems like a better solution to not do anything and allow APIG to join them with a comma – at least that way there isn't any data loss, and your app can adjust to get the values.

Related: https://github.com/brefphp/bref/issues/818

mnapoli commented 9 months ago

Hi, I'm not sure I understand everything.

Could you clarify with:

Thanks!

timkelty commented 9 months ago

What currently happens

Given a response with multi-value headers (2 unique headers with the same name), Bref will only keep the last header: https://github.com/brefphp/bref/blob/master/src/Event/Http/HttpResponse.php#L37

Eg, given

x-foo: bar
x-foo: baz

The APIG response will be constructed with only x-foo: baz

What I expect to happen

I expect headers with duplicate names to be joined with a ,, which is API Gateway v2's default behavior:

So, x-foo: bar,baz

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

So, it seems like Bref shouldn't do any special handling for these headers, and instead rely on APIG's default handling.