Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP headers casing #57

Open
jplagostena opened this issue Dec 20, 2023 · 0 comments
Open

HTTP headers casing #57

jplagostena opened this issue Dec 20, 2023 · 0 comments

Comments

@jplagostena
Copy link

Hi everyone,
we are having some problems with the case of the headers.

The Client/Response class has to decide if the body has to be parsed as json:

public function __construct(
        $status_code,
        $reason_phrase,
        $body,
        array  $headers = []
    )
    {
        $this->status_code   = intval($status_code);
        $this->reason_phrase = $reason_phrase;
        $this->body          = $body;
        $this->headers       = $headers;

        // Store decoded JSON data, if present
        if (
            !empty( $this->headers['Content-Type'] )
            && mb_strpos( $this->headers['Content-Type'][0], 'application/json;' ) !== false
        ) {
            $this->data = json_decode( $this->body, true );

            if ( !empty( $this->data['error'] ) ) {
                $this->error = $this->data['error'];
            }
        }
    }

now our problem is that the response has all headers in lowercase, so the body is never parsed and the data field is never fulfilled. The solution looks easy but before I wanted to ask if no one had to solve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant