Currently i am building my own php framework and i am now creating an implementation of the PHP-FIG PSR-7 MessageInterface. In specific the withHeader method. It states that the method could trow an exeption: \InvalidArgumentException for invalid header names or values.
So i am wondering, when is a header valid or invalid? Same for the values. Or should i accept any header, and any header value? That could be dangerous right?
I now you can generaly say that if a header has multiple values, they are comma seperated. But that does not allways apply. If i look at a user-agent header for example, the value itself sometimes contains a comma. But you should treat it as a single value.
Indeed, it's "dangerous" to pass a header name - as argument of
withHeader()
, whichNULL
The same applies to the header value argument. It must be an array or a string (representing only one value, not a comma-separated list of values!).
As for the implementation of the
withHeader
method: