Symfony 5 – Using Response::HTTP_CREATED in JsonResponse returns Set-Cookie

I made two tests with exactly the same code except the returned status code of my request (200 for one test, and 201 for another test).

Here the only difference between my two tests:

return new JsonResponse(["id" => $transaction->getId()], Response::HTTP_OK);


return new JsonResponse(["id" => $transaction->getId()], Response::HTTP_CREATED);

In the first case, no Set-Cookie header is returned into the response. In the second case, a Set-Cookie header is returned.

Something like:

Set-Cookie: sf_redirect=%7B%22token%22%3A%221a18a8%22%2C%22route%22%3A%22new_transaction%22%2C%22method%22%3A%22POST%22%2C%22controller%22%3A%7B%22class%22%3A%22App%5C%5CController%5C%5CTransactionsController%22%2C%22method%22%3A%22new%22%2C%22file%22%3A%22%5C%2Fvar%5C%2Fwww%5C%2Fsymfony5%5C%2Fsrc%5C%2FController%5C%2FTransactionsController.php%22%2C%22line%22%3A46%7D%2C%22status_code%22%3A201%2C%22status_text%22%3A%22Created%22%7D; path=/; httponly; samesite=lax

I do exactly the same curl request in both cases.

I wonder why this Set-Cookie header is returned when I use a CREATED status code.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *