Skip to content

Headers are Case Sensitive - Saloon Response Class #482

Closed

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

Activity

  1. added theissue type on Jun 21, 2025
  2. lamberttraccard commented on Sep 1, 2025

    @lamberttraccard

    Just been bitten by this 😓

  3. JonPurvis commented on Feb 26, 2026

    @JonPurvis
    Contributor

    Hey @Cbrad24, @lamberttraccard

    We merged #534 earlier this evening which I think should resolve this?

  4. dvdheiden commented on Mar 1, 2026

    @dvdheiden

    @JonPurvis I am not convinced that solves this specific issue, as the mentioned PR only changed it when detecting the response type and not the header method itself. When we look at the headers method on the Response class, it still does:

    public function header(string $header): string|array|null
    {
        return $this->headers()->get($header);
    }
    

    That line is replaced in the PR with accessing the PSR response.

    So, that's why I think the $response->header('Content-Type') and $response->header('content-type') still behave differently.

  5. JonPurvis commented on Mar 2, 2026

    @JonPurvis
    Contributor

    Whoops, my bad!

    I saw "Case Sensitive" and went into autopilot mode 😆

    I've created #535 and will try to get it merged this evening and then get a patch version released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions