Saltar al contenido

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?

preguntada hace un año599 visualizaciones
1 Respuesta
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
respondido hace un año
EXPERTO
revisado hace un año

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.