跳至內容

multiple Set-Cookie in API Gateway's mock response

0

How can I mock API Gateway response in the management console and set multiple Set-Cookie values in the response header?

已提問 1 年前檢視次數 600 次
1 個回答
1

I guess mocking API Gateway responses in the AWS Management Console doesn't currently allow directly setting multiple Set-Cookie headers. However, there's a workaround you can use to achieve this by -

1/ Mocking with a Method Response.

2/ Override Response Headers - Use Edit option.

3/ Using Case-Sensitive Header Names (Not Recommended): API Gateway is case-insensitive for request headers, but you can exploit this behavior for response headers . Define multiple Set-Cookie headers with different capitalizations (e.g., Set-Cookie, SET-COOKIE, sEt-Cookie). Each variation will be treated as a separate header, allowing you to set multiple cookies.

"message": "This is a mocked response", "headers": { "Set-Cookie": "cookie1=value1; Expires=Wed, 13 Jun 2024 08:20:00 GMT; Path=/", "SET-COOKIE": "cookie2=value2; Expires=Wed, 13 Jun 2024 08:20:00 GMT; Path=/", "sEt-Cookie": "cookie3=value3; Expires=Wed, 13 Jun 2024 08:20:00 GMT; Path=/" }

OR Using a Single Set-Cookie Header with Multiple Cookies (Recommended):

This approach leverages the standard way cookies are sent in HTTP responses: a single Set-Cookie header with multiple comma-separated cookie definitions.

"Set-Cookie": "cookie1=value1; Expires=Wed, 13 Jun 2024 08:20:00 GMT; Path=/; cookie2=value2; Expires=Wed, 13 Jun 2024 08:20:00 GMT; Path=/; cookie3=value3; Expires=Wed, 13 Jun 2024 08:20:00 GMT; Path=/"
AWS
已回答 1 年前
專家
已審閱 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。