Direkt zum Inhalt

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 Antwort
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
beantwortet vor einem Jahr
EXPERTE
überprüft vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.