Skip to content

Headers are Case Sensitive - Saloon Response Class #482

Description

@Cbrad24

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions