Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 979b307

Browse filesBrowse files
[HttpKernel] Allow using #[WithHttpStatus] for setting status code and headers
1 parent f8f0f7c commit 979b307
Copy full SHA for 979b307

File tree

Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed

‎reference/configuration/framework.rst

Copy file name to clipboardExpand all lines: reference/configuration/framework.rst
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,6 +3611,27 @@ use the configuration of the first exception that matches ``instanceof``:
36113611
log_level: 'debug'
36123612
status_code: 422
36133613
3614+
You can map a status code and a set of headers to an exception thanks
3615+
to the ``#[WithHttpStatus]`` attribute on the exception class:
3616+
3617+
.. code-block:: php
3618+
3619+
namespace App\Exception;
3620+
3621+
use Symfony\Component\HttpKernel\Attribute\WithHttpStatus;
3622+
3623+
#[WithHttpStatus(422, [
3624+
'Retry-After' => 10,
3625+
'X-Custom-Header' => 'header-value',
3626+
])]
3627+
class CustomException extends \Exception
3628+
{
3629+
}
3630+
3631+
.. versionadded:: 6.3
3632+
3633+
The ``#[WithHttpStatus]`` attribute was introduced in Symfony 6.3.
3634+
36143635
.. _`HTTP Host header attacks`: https://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html
36153636
.. _`Security Advisory Blog post`: https://symfony.com/blog/security-releases-symfony-2-0-24-2-1-12-2-2-5-and-2-3-3-released#cve-2013-4752-request-gethost-poisoning
36163637
.. _`PhpStormProtocol`: https://github.com/aik099/PhpStormProtocol

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.