zendframework / zend-http

Http component from Zend Framework
BSD 3-Clause "New" or "Revised" License
134 stars 85 forks source link

Do not raise exception on header retrival for invalid header lines #147

Closed michalbundyra closed 6 years ago

michalbundyra commented 6 years ago

Fixes #146

weierophinney commented 6 years ago

One thought I've had since posting #146 is that we could potentially check for exceptions in lazyLoadHeader(), and, if detected, attempt to create a GenericHeader instance. The main problem with that approach is that if the user was expecting a more specific header type, and planned to call methods on it, they will now get a PHP fatal error due to the method not existing.

As such, another option would be to allow access to the raw header lines somehow within the Headers class, so that users can at least introspect later if they are unsure why they are not getting a value for a header they expect.

michalbundyra commented 6 years ago

As discussed with @weierophinney on slack we decided to change it slightly to have the following behaviour:

$headers->has(‘User-Agent’) -> false
$headers->has(‘useragent’)  -> true
$headers->get(‘User-Agent’) -> false
$headers->get(‘useragent’)  -> the generic header

Exception shouldn't be raised in any of these cases.

weierophinney commented 6 years ago

Thanks, @webimpress!