Headers

Both request and response messages contain HTTP headers.

Complex Headers

Some headers contain additional key value pair information. For example, Link headers contain a link and several key value pairs:

  1. <http://foo.com>; rel="thing"; type="image/jpeg"

Guzzle provides a convenience feature that can be used to parse these types of headers:

  1. use GuzzleHttp\Message\Request;
  2. $request = new Request('GET', '/', [
  3. 'Link' => '<http:/.../front.jpeg>; rel="front"; type="image/jpeg"'
  4. ]);
  5. $parsed = Request::parseHeader($request, 'Link');
  6. var_export($parsed);

Will output:

  1. array (
  2. 0 =>
  3. array (
  4. 0 => '<http:/.../front.jpeg>',
  5. 'rel' => 'front',
  6. 'type' => 'image/jpeg',
  7. ),
  8. )

The result contains a hash of key value pairs. Header values that have no key (i.e., the link) are indexed numerically while headers parts that form a key value pair are added as a key value pair.

See Request and Response Headers for information on how the headers of a request and response can be accessed and modified.