Skip to content

Commit 35e30b7

Browse files
committed
minor #9668 Documented the HeaderUtils class (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #9668). Discussion ---------- Documented the HeaderUtils class This fixes #9655. Commits ------- 3d86e46 Documented the HeaderUtils class
2 parents bd6f4d3 + 3d86e46 commit 35e30b7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

components/http_foundation.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,39 @@ the previous requests.
241241
an exception in Symfony 5.0 when the session is ``null``. Check for an existing session
242242
first by calling :method:`Symfony\\Component\\HttpFoundation\\Request::hasSession()`.
243243

244+
Processing HTTP Headers
245+
~~~~~~~~~~~~~~~~~~~~~~~
246+
247+
.. versionadded:: 4.1
248+
The ``HeaderUtils`` class was introduced in Symfony 4.1.
249+
250+
Processing HTTP headers is not a trivial task because of the escaping and white
251+
space handling of their contents. Symfony provides a
252+
:class:`Symfony\\Component\\HttpFoundation\\HeaderUtils` class that abstracts
253+
this complexity and defines some methods for the most common tasks::
254+
255+
use Symfony\Component\HttpFoundation\HeaderUtils;
256+
257+
// Splits an HTTP header by one or more separators
258+
HeaderUtils::split('da, en-gb;q=0.8', ',;')
259+
// => array(array('da'), array('en-gb'), array('q', '0.8'))
260+
261+
// Combines an array of arrays into one associative array
262+
HeaderUtils::combine(array(array('foo', 'abc'), array('bar')))
263+
// => array('foo' => 'abc', 'bar' => true)
264+
265+
// Joins an associative array into a string for use in an HTTP header
266+
HeaderUtils::toString(array('foo' => 'abc', 'bar' => true, 'baz' => 'a b c'), ',')
267+
// => 'foo=bar, baz, baz="a b c"'
268+
269+
// Encodes a string as a quoted string, if necessary
270+
HeaderUtils::quote('foo "bar"')
271+
// => 'foo \"bar\"'
272+
273+
// Decodes a quoted string
274+
HeaderUtils::unquote('foo \"bar\"')
275+
// => 'foo "bar"'
276+
244277
Accessing ``Accept-*`` Headers Data
245278
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246279

0 commit comments

Comments
 (0)