Skip to content

Documented the default values of Accept headers #9292

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

Merged
merged 1 commit into from
Feb 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion components/http_foundation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,19 @@ If you need to get full access to parsed data from ``Accept``, ``Accept-Language
$accepts = AcceptHeader::fromString($request->headers->get('Accept'))
->all();

The default values that can be optionally included in the ``Accept-*`` headers
are also supported::

$acceptHeader = 'text/plain;q=0.5, text/html, text/*;q=0.8, */*;q=0.3';
$accept = AcceptHeader::fromString($acceptHeader);

$quality = $accept->get('text/xml')->getQuality(); // $quality = 0.8
$quality = $accept->get('application/xml')->getQuality(); // $quality = 0.3

.. versionadded:: 4.1
The support of default values in the ``Accept-*`` headers was introduced in
Symfony 4.1.

Accessing other Data
~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -403,7 +416,7 @@ of methods to manipulate the HTTP headers related to the cache:
.. note::

The methods :method:`Symfony\\Component\\HttpFoundation\\Response::setExpires`,
:method:`Symfony\\Component\\HttpFoundation\\Response::setLastModified` and
:method:`Symfony\\Component\\HttpFoundation\\Response::setLastModified` and
:method:`Symfony\\Component\\HttpFoundation\\Response::setDate` accept any
object that implements ``\DateTimeInterface``, including immutable date objects.

Expand Down