Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added a note about request accept-* headers parsing. #1868

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 2 commits into from
Nov 16, 2012
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