Skip to content

Commit 86e7cdf

Browse files
author
Nghĩa Nguyễn Ngọc
committed
feat(events): add MultiValueHeaders to LambdaFunctionURLResponse
AWS Lambda Function URLs can return multiple values for the same header key (e.g. multiple Set-Cookie headers). Without MultiValueHeaders, callers had to work around the single-value Headers map and could not set more than one cookie in a single response. Adds MultiValueHeaders map[string][]string with omitempty, matching the shape already present on APIGatewayProxyResponse and APIGatewayV2HTTPResponse, and adds a round-trip marshaling test with a multi-cookie fixture. Fixes #556
1 parent 815d21f commit 86e7cdf

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

events/lambda_function_urls.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ type LambdaFunctionURLRequestContextHTTPDescription struct {
6161

6262
// LambdaFunctionURLResponse configures the HTTP response to be returned by Lambda Function URL for the request.
6363
type LambdaFunctionURLResponse struct {
64-
StatusCode int `json:"statusCode"`
65-
Headers map[string]string `json:"headers"`
66-
Body string `json:"body"`
67-
IsBase64Encoded bool `json:"isBase64Encoded"`
68-
Cookies []string `json:"cookies"`
64+
StatusCode int `json:"statusCode"`
65+
Headers map[string]string `json:"headers"`
66+
MultiValueHeaders map[string][]string `json:"multiValueHeaders,omitempty"`
67+
Body string `json:"body"`
68+
IsBase64Encoded bool `json:"isBase64Encoded"`
69+
Cookies []string `json:"cookies"`
6970
}
7071

7172
// LambdaFunctionURLStreamingResponse models the response to a Lambda Function URL when InvokeMode is RESPONSE_STREAM.

events/lambda_function_urls_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ func TestLambdaFunctionURLRequestMarshaling(t *testing.T) {
6060
assert.JSONEq(t, string(inputJSON), string(outputJSON))
6161
}
6262

63+
func TestLambdaFunctionURLResponseMultiValueHeadersMarshaling(t *testing.T) {
64+
inputJSON, err := ioutil.ReadFile("./testdata/lambda-urls-response-multi-value-headers.json")
65+
if err != nil {
66+
t.Errorf("could not open test file. details: %v", err)
67+
}
68+
69+
var inputEvent LambdaFunctionURLResponse
70+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
71+
t.Errorf("could not unmarshal event. details: %v", err)
72+
}
73+
74+
require.Equal(t, []string{"a=1; Path=/", "b=2; Path=/"}, inputEvent.MultiValueHeaders["Set-Cookie"])
75+
76+
outputJSON, err := json.Marshal(inputEvent)
77+
if err != nil {
78+
t.Errorf("could not marshal event. details: %v", err)
79+
}
80+
81+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
82+
}
83+
6384
func TestLambdaFunctionURLStreamingResponseMarshaling(t *testing.T) {
6485
for _, test := range []struct {
6586
name string
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"statusCode": 200,
3+
"headers": {
4+
"Content-Type": "application/json"
5+
},
6+
"multiValueHeaders": {
7+
"Set-Cookie": ["a=1; Path=/", "b=2; Path=/"]
8+
},
9+
"body": "",
10+
"cookies": [],
11+
"isBase64Encoded": false
12+
}

0 commit comments

Comments
 (0)