saloon icon indicating copy to clipboard operation
saloon copied to clipboard

Headers are Case Sensitive - Saloon Response Class

Open Cbrad24 opened this issue 10 months ago • 1 comments

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

Cbrad24 avatar Feb 14 '25 07:02 Cbrad24

Just been bitten by this 😓

lamberttraccard avatar Sep 01 '25 15:09 lamberttraccard