Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change status code of response #317

Closed
nicolaspetitjean opened this issue Feb 11, 2018 · 7 comments
Closed

Change status code of response #317

nicolaspetitjean opened this issue Feb 11, 2018 · 7 comments

Comments

@nicolaspetitjean
Copy link
Contributor

Hello

I look for for a way to change status code of response. I'm using an event listener which have to return an EmptyResponse, but not way to change the status code (in my case, i'd like to return 201 instead of 200, because i create a new entity after the upload.
Regards !

@bytehead
Copy link
Member

If you get the Response object in your event listener you can just change the status code returned:

$response = $event->getResponse();
$response->setStatusCode(Response::HTTP_CREATED);
$event->setResponse($response);

@nicolaspetitjean
Copy link
Contributor Author

Well, i thought about that, but those two methods doesn't exist in EmptyResponse. Maybe i'm wrong, but when you do $response = $event->getResponse(); you get an EmptyResponse, not a Response.

@bytehead
Copy link
Member

I see. There's no simple way to do it 😏
You could try to register your custom controller to overwrite the upload() method.
@sheeep any thoughts on this?

@sheeep
Copy link
Contributor

sheeep commented Feb 13, 2018

@nicolaspetitjean Can you tell me what kind of uploader you're using?

This is indeed not easily solvable, as the development of the Response-part was - in hindsight - not my brightest moment. I assume the easiest solution is to just create a custom controller.

@nicolaspetitjean
Copy link
Contributor Author

@sheeep i'm using dropzone. I think EmptyRespponse should extends Symfony's Response ?

@nicolaspetitjean
Copy link
Contributor Author

nicolaspetitjean commented Feb 18, 2018

Looks like i'm not the only one who have such ideas #71

@stale
Copy link

stale bot commented Mar 28, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 28, 2020
@stale stale bot closed this as completed Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants