nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 298 forks source link

Body parsing broken in 0.3.0 #285

Closed atymic closed 4 years ago

atymic commented 4 years ago

I've inherited a project using this library, and upon updating from 0.2 to 0.3 json responses aren't being parsed as they were previously in 0.2. I'll do a bit of investigating to try figure out why, but for the moment i've pinned it back to 0.2.

atymic commented 4 years ago

Ok, so I figured out the issue. The library parses the incoming headers straight from curl, and adds them to the array in whatever casing the appear as.

In 0.2.x, the behavior was lowercase all of the incoming headers, and then lowercase the requested header name before trying to grab it out of the array. This means that whatever the casing in the response, the header can always be found.

In 0.3.x, this behaviour was changed to no longer modify the header casing when parsing the response, and also removing the lowercasing when accessing headers. This means that unless the header is cased exactly the same as requested, it cannot be accessed. This is wrong according to the HTTP spec (and other HTTP implementations).

In HTTP2, all headers are lowercase, meaning that mime parsing will never work in the package.

I'm going to PR a failing test and then a fix when I get a chance :)

nategood commented 4 years ago

Resolved