Skip to content
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
29 changes: 29 additions & 0 deletions components/http_foundation/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,35 @@ the
method tells you if the request contains a Session which was started in one of
the previous requests.

Accessing `Accept-*` Headers Data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Member

Choose a reason for hiding this comment

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

I think you need to mention that the Request class has methods that do the work for you and list them.

You can easily access basic data extracted from ``Accept-*`` headers
by using following methods:

* :method:`Symfony\\Component\\HttpFoundation\\Request::getAcceptableContentTypes`:
Returns the list of accepted content types ordered by descending quality;

* :method:`Symfony\\Component\\HttpFoundation\\Request::getLanguages`:
Returns the list of accepted languages ordered by descending quality;

* :method:`Symfony\\Component\\HttpFoundation\\Request::getCharsets`:
Returns the list of accepted languages ordered by descending quality;

If you need to egt full access to parsed data from ``Accept``, ``Accept-Language``,
Copy link
Member

Choose a reason for hiding this comment

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

typo here: get

``Accept-Charset`` or ``Accept-Encoding``, you can use
:class:`Symfony\\Component\\HttpFoundation\\AcceptHeader` utility class::

$accept = AcceptHeader::fromString($request->headers->get('Accept'));
if ($accept->has('text/html') {
$item = $accept->get('html');
$charset = $item->getAttribute('charset', 'utf-8');
$quality = $item->getQuality();
}

// accepts items are sorted by descending quality
$accepts = AcceptHeader::fromString($request->headers->get('Accept'))->all();

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

Expand Down