8000 [Kernel] deprecate X-Status-Code · Issue #12343 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Kernel] deprecate X-Status-Code #12343

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

Closed
Tobion opened this issue Oct 28, 2014 · 6 comments
Closed

[Kernel] deprecate X-Status-Code #12343

Tobion opened this issue Oct 28, 2014 · 6 comments

Comments

@Tobion
Copy link
Contributor
Tobion commented Oct 28, 2014

The handling of the X-Status-Code header in der kernel introduced in 788e5eb is a hack and just introduced as a workaround. First of all it's magic (why this header?) and second of all it disallows to actually return such a header because it's removed automatically. So you cannot send a response with this header even if you need to.
It should be deprecated and replaced by a better solution. Alternatives:

  1. practically there already exists a solution without this magic header: http://stackoverflow.com/a/26520225/1382727
  2. or better add a GetResponseForExceptionEvent::allowSuccessfulResponse setter/getter to the event. When true (default false), it will use the Response status code even if it's a 2xx for an exception.
@desarrolla2
Copy link
Contributor

I will start with this issue on Hackday

@desarrolla2
Copy link
Contributor

Hi @Tobion, this header is been used not only on exceptions also used in

$response->headers->set('X-Status-Code', 401);
so im thinking in solution to remove this.

@stof
Copy link
Member
stof commented Jan 3, 2015

@desarolla2 have you got any result on this ?

@desarrolla2
Copy link
Contributor

Nop, sorry.

@devsdmf
Copy link
devsdmf commented Mar 30, 2016

Updates ?

@jameshalsall
Copy link
Contributor

@devsdmf I've created a PR with this work

fabpot added a commit that referenced this issue Mar 1, 2017
…ative (jameshalsall)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[HttpKernel] Deprecate X-Status-Code for better alternative

| Q | A |
| --- | --- |
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | yes |
| Tests pass? | yes |
| Fixed tickets | #12343 |
| License | MIT |
| Doc PR | symfony/symfony-docs#6948 |

This marks the X-Status-Code header method of setting a custom response status
code in exception listeners for a better alternative. There is now a new method
on the `GetResponseForExceptionEvent` that allows successful status codes in
the response sent to the client.

The old method of setting the X-Status-Code header will now throw a deprecation warning.

Instead, in your exception listener you simply call `GetResponseForExceptionEvent::allowCustomResponseCode()` which will tell the Kernel not to override the status code of the event's response object.

Currenty the `X-Status-Code` header will still be removed, so as not to change the existing behaviour, but this is something we can remove in 4.0.

TODO:
- [x] Replace usage of X-Status-Code in `FormAuthenticationEntryPoint`
- [x] Open Silex issue
- [x] Rename method on the response
- [x] Ensure correct response code is set in `AuthenticationEntryPointInterface` implementations
- [x] Ensure the exception listeners are marking `GetResponseForExceptionEvent` as allowing a custom response code
- [x] In the Security component we should only use the new method of setting a custom response code if it is available, and fall back to the `X-Status-Code` method

Commits
-------

cc0ef28 [HttpKernel] Deprecate X-Status-Code for better alternative
@fabpot fabpot closed this as completed Mar 1, 2017
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

7 participants
0