zendframework / zend-diactoros

PSR-7 HTTP Message implementation
BSD 3-Clause "New" or "Revised" License
1.56k stars 152 forks source link

MessageTrait::setHeaders looses original header name casing. #300

Closed rbchasesc closed 6 years ago

rbchasesc commented 6 years ago

According to the PSR-7 MessageInterface - Case-insensitive header field names, it states:

Despite that headers may be retrieved case-insensitively, the original case MUST be preserved by the implementation, in particular when retrieved with getHeaders().

However, the \Zend\Diactoros\MessageTrait::setHeaders method at Line 327 is performing a strtolower on each header name before writing the headers array to to the headers protected variable. In doing so, the original header names' case is lost, which appears to be in violation of PSR-7. If this is a violation and to be corrected, it will require changes to other header related methods as they are all assuming the normalization to lowercase for the names has been completed when accessing the headers variable.

froschdesign commented 6 years ago

@rbchasesc

…before writing the headers array to to the headers protected variable.

Sorry, this is wrong. Look at the next line:

https://github.com/zendframework/zend-diactoros/blob/bb833f8e92297be103bf6cd3fc25219474bbf0d0/src/MessageTrait.php#L327-L328

$headerNames !== $headers

See also:

https://github.com/zendframework/zend-diactoros/blob/bb833f8e92297be103bf6cd3fc25219474bbf0d0/src/MessageTrait.php#L20-L32

weierophinney commented 6 years ago

As @froschdesign notes, we do keep track of the original casing, and that casing is used when emitting or serializing headers. We normalize the names in $headers to allow simplified lookups, but store the originally provided values in $headerNames, which is used for representation.