0

I have the following request:

2017-04-05 06:53:31 Error: Cake\Http\ServerRequest Object
(
    ...
    [_environment:protected] => Array
        (
            [HTTP_REGISTRATION] => eur73_9lhfQ:...SJMryPxCNzKcqSufdpFMOaux
            ...
        )

    [_detectorCache:protected] => Array
        (
            [ajax] => 
            [get] => 1
            [head] => 
            [options] => 
            [post] => 
        )

    [uri:protected] => Zend\Diactoros\Uri Object
        (
            [allowedSchemes:protected] => Array
                (
                    [http] => 80
                    [https] => 443
                )
            ...

        )
    ...
)

$this->request->header['registration'] returns:

eur73_9lhfQ:...SJMryPxCNzKcqSufdpFMOaux

as string

$this->request->getHeader('registration') returns:

[Registration] => Array
    (
        [0] => eur73_9lhfQ:...SJMryPxCNzKcqSufdpFMOaux
    )

Why does it return an array?

ndm
  • 59,784
  • 9
  • 71
  • 110
fralbo
  • 2,534
  • 4
  • 41
  • 73

1 Answers1

1

The HTTP standard allows multiple headers with the same field name to be present in case all values of that header can be expressed as a single, comma separated string (Set-Cookie is an exception to that rule, it cannot express multiple values in a single string, but in practice does still appear multiple times in order to define multiple cookies).

In order to support this in a convenient way, the PSR-7 standard (which \Cake\Http\ServerRequest complies to) defines the getHeader() method to return header values as arrays. The complement to that is the getHeaderLine() method, which is ment to return multiple values as a single, comma separated string.

See also

Community
  • 1
  • 1
ndm
  • 59,784
  • 9
  • 71
  • 110