Headers are Case Sensitive - Saloon Response Class
First off, love the framework, has brought law and order to my wild west of API code ðŸ¤
I recently however had an issue with headers. The HTTP standard defines that HTTP headers are designed to be case insensitive. Meaning it shouldn't matter if the API I am consuming presents its headers in Title-Case or in lower-case. Developers are expected to present headers in lowercase, but code should be assessing them all in lowercase regardless.
As an example, if I sent a header X-My-Custom-Header:
When using Saloon, you will get different results when using $response->header('x-my-custom-header'); vs using Guzzle/PSR7's $response->getPsrResponse()->getHeader('x-my-custom-header');, due to the way Guzzle lowercases all headers and lowercases users input to the function.
x-my-custom-header: custom-value
$response = $connector->send(new Request);
$response->header('X-My-Custom-Header');
// returns null
$response->getPsrResponse()->getHeader('X-My-Custom-Header');
// returns "custom-value"
The reason I think this is an issue?
An API I was consuming recently changed all its headers to lowercase to align better with standards. This caused my code to break as it was dependant on the headers being in Title-Case.
https://developer.xurrent.com/v1/general/changelog/#october-12-2024
Further reading here: https://www.php-fig.org/psr/psr-7/#12-http-headers https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
Just been bitten by this 😓