@@ -241,6 +241,39 @@ the previous requests.
241
241
an exception in Symfony 5.0 when the session is ``null ``. Check for an existing session
242
242
first by calling :method: `Symfony\\ Component\\ HttpFoundation\\ Request::hasSession() `.
243
243
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
+
244
277
Accessing ``Accept-* `` Headers Data
245
278
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246
279
0 commit comments