zammad-api-client-php icon indicating copy to clipboard operation
zammad-api-client-php copied to clipboard

HTTP headers casing

Open jplagostena opened this issue 2 years ago • 0 comments

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.

jplagostena avatar Dec 20 '23 22:12 jplagostena