Symfony JsonResponse with Location header results in 302

113 views Asked by At

I am trying to return a json response which also has a location header. Before the request was returning this

return new Response('', Response::HTTP_CREATED, ['Location' => $url]);

I need to add an ID as part of the request body so I decided to just convert it to JsonResponse

 return new JsonResponse(['createdId' => $createdId], Response::HTTP_CREATED, ['Location' => $url]);

To my surprise instead of a 201 code it returns 302. I can add the url to the json body and let front-end handle the redirect, but there should be a better way?

1

There are 1 answers

0
Tomasz Kartasiński On

If I were you, I would check what the url and createdId variables contain before sending. Their content may influence the result.