Skip to content

[HttpKernel] minor: add ability to construct with headers on http exceptions #22228

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

Conversation

gsdevme
Copy link
Contributor

@gsdevme gsdevme commented Mar 30, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This adds the ability to set the headers for the exception within the constructor.

With alot of the following exceptions its sometimes very useful to be able to set the headers. For example with a reverse proxy cache (Varnish) if you want to match the Retry-After with a Varnish cache header to protect the backend.

I see that setHeaders() did get added 6a1080f but that means the exception needs to be assigned to a variable and set and then thrown, it also doesn't merge with the existing header set in some of the constructors.

I've chosen to array_merge() where key/values were being set within the constructor as I think this is the most useful and 'correct' whereas setHeaders is explicit that its setting not amending or adding to.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 3, 2017

All the array_merge could be replaced by a simple affectation: $headers['Foo'] = 'bar';

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Apr 3, 2017
@gsdevme
Copy link
Contributor Author

gsdevme commented Apr 7, 2017

@nicolas-grekas Thanks! Good spot, will update.

@gsdevme gsdevme force-pushed the minor/add-ability-to-set-headers-on-exceptions branch from c9fd589 to 098006f Compare April 7, 2017 10:35
Copy link
Contributor

@Nek- Nek- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gsdevme
Copy link
Contributor Author

gsdevme commented Apr 9, 2017

An oversight, will fix the others up also.

@nicolas-grekas
Copy link
Member

Status: needs work

@gsdevme gsdevme force-pushed the minor/add-ability-to-set-headers-on-exceptions branch from 098006f to 612fb59 Compare April 15, 2017 00:12
@gsdevme
Copy link
Contributor Author

gsdevme commented Apr 20, 2017

Updated.

@fabpot
Copy link
Member

fabpot commented Oct 8, 2017

Thank you @gsdevme.

@fabpot fabpot merged commit 612fb59 into symfony:master Oct 8, 2017
fabpot added a commit that referenced this pull request Oct 8, 2017
…ers on http exceptions (gsdevme)

This PR was merged into the 4.0-dev branch.

Discussion
----------

[HttpKernel] minor: add ability to construct with headers on http exceptions

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

This adds the ability to set the headers for the exception within the constructor.

With alot of the following exceptions its sometimes very useful to be able to set the headers. For example with a reverse proxy cache (Varnish) if you want to match the `Retry-After` with a Varnish cache header to protect the backend.

I see that `setHeaders()` did get added 6a1080f but that means the exception needs to be assigned to a variable and set and then thrown, it also doesn't merge with the existing header set in some of the constructors.

~~I've chosen to `array_merge()` where key/values~~ were being set within the constructor as I think this is the most useful and 'correct' whereas `setHeaders` is explicit that its setting not amending or adding to.

Commits
-------

612fb59 [HttpKernel] minor: add ability to construct with headers on http exceptions
@fabpot fabpot mentioned this pull request Oct 19, 2017
@gsdevme
Copy link
Contributor Author

gsdevme commented Mar 30, 2018

For future reference although this has a milestone of 3.4, its only in 4.0+

@gsdevme gsdevme deleted the minor/add-ability-to-set-headers-on-exceptions branch March 30, 2018 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants