Skip to content

Exception due to Zencoder response headers being lower-case now #29

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

Closed
OlafZwe opened this issue Nov 9, 2018 · 8 comments
Closed

Exception due to Zencoder response headers being lower-case now #29

OlafZwe opened this issue Nov 9, 2018 · 8 comments

Comments

@OlafZwe
Copy link

OlafZwe commented Nov 9, 2018

This most recent zencoder-php SDK throws the following exception as a result of any API requests:
Response header is missing Content-Type

The reason appears to be that the SDK checks for the following response header: Content-Type. A recent change to Zencoder appears to have resulted in all response headers being returned in lower case. So the SDK is not finding the new content-type lower case header and throwing the above exception.

A quick and dirty fix we applied was to use the following code in the Services/Zencoder.php _processResponse($response) function (line 234):

if (empty($headers['Content-Type'])) {
    if (empty($headers['content-type'])) {
        throw new Services_Zencoder_Exception('Response header is missing Content-Type', $body);
    } else {
        $headers['Content-Type'] = $headers['content-type'];
    }
}
@jgreer
Copy link
Contributor

jgreer commented Nov 9, 2018

The Zencoder API returns Content-Type using that capitalization. Can you provide an example request (with authentication obscured) where you see that happening?

It might be that you've got a proxy server or library that's altering the headers.

@GC-Mark
Copy link

GC-Mark commented Nov 12, 2018

We are seeing exactly the same thing with our integration. Since 3-4 days ago, the response headers are all lowercase so it throws the Services_Zencoder_Exception exception.

We haven't changed anything on our side that I know of that could have affected this.

@GC-Mark
Copy link

GC-Mark commented Nov 12, 2018

...having said that, when we run the same code on our local testing servers, the headers used are in the correct Upper/Lower case format

@OlafZwe
Copy link
Author

OlafZwe commented Nov 15, 2018

After doing some additional testing, we found that the Zencoder servers indeed return the correct header format (capitalized), by testing on our server with the following command, curl -v -H 'zencoder-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' https://app.zencoder.com/api/v2/outputs/2079092822/progress.json:

< HTTP/1.1 200 OK
< Date: Thu, 15 Nov 2018 13:41:54 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 20
< Connection: keep-alive
< Server: ZenServer 0.2.0

So the issue does not appear to be a proxy.

However, the curl command used in the zencoder-php library returns lower-case headers. We tested this using the following simplified script:

<?php

$ch = curl_init();
curl_setopt_array($ch, array (
    CURLOPT_URL               => "https://app.zencoder.com/api/v2/outputs/2079092822/progress.json",
    CURLOPT_HTTPGET           => 1,
    CURLOPT_HEADER            => 1,
    CURLOPT_RETURNTRANSFER    => 1,
    CURLOPT_CONNECTTIMEOUT    => 30,
    CURLOPT_TIMEOUT           => 60,
    CURLOPT_SSL_VERIFYPEER    => 1,
    CURLOPT_SSL_VERIFYHOST    => 2,
    CURLOPT_HTTPHEADER        => array (
        "zencoder-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    )
));

$result=curl_exec($ch);
print_r($result);
curl_close($ch);

and got the following output (truncated):

HTTP/2 200
date: Thu, 15 Nov 2018 13:53:28 GMT
content-type: application/json; charset=utf-8
content-length: 20
server: ZenServer 0.2.0
...

(note the lower-case headers)

We suspect this might be a problem with a specific PHP and/or curl version, so here are the PHP and curl versions:

php --version
PHP 7.1.24
curl_version();
[version_number] => 474624
[age] => 4
[features] => 11518877
[ssl_version_number] => 0
[version] => 7.62.0
[host] => x86_64-redhat-linux-gnu
[ssl_version] => OpenSSL/1.0.2p
[libz_version] => 1.2.3

Is there a specific PHP 7 version (or curl version) which zencoder-php is verified on, so we can update to that version?

@jgreer
Copy link
Contributor

jgreer commented Nov 15, 2018

Looking at this further, the PHP version is using HTTP 2 instead of 1.1, and the HTTP 2 specification requires that headers are lower-cased. So that seems to be what's causing the difference.

https://httpwg.org/specs/rfc7540.html#HttpHeaders - "Just as in HTTP/1.x, header field names are strings of ASCII characters that are compared in a case-insensitive fashion. However, header field names MUST be converted to lowercase prior to their encoding in HTTP/2. A request or response containing uppercase header field names MUST be treated as malformed (Section 8.1.2.6)."

This library obviously predates HTTP/2 so that wasn't a consideration in the original implementation. But hopefully we can push an update sometime soon that compares in case-insensitive fashion. In the meantime, it looks like the code in this issue is a functional workaround.

@slengyel-lnx
Copy link

Same issue here with the lowercased header values using PHP 7.2. Would be great to have an updated version which addresses this bug.

@glensc
Copy link

glensc commented Sep 5, 2019

@OlafZwe I've submitted your change as Pull Request: #33

I think it's rather related to curl than PHP version, as I have PHP 5.3 and recent curl, and have lowercased headers in the response.

# curl --version
curl 7.65.0 (x86_64-pld-linux-gnu) libcurl/7.65.0 OpenSSL/1.1.1c zlib/1.2.11 brotli/1.0.7 c-ares/1.14.0 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.1.1) libssh2/1.8.2 nghttp2/1.38.0 librtmp/2.3
Release-Date: 2019-05-22
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets

@zencoder: could somebody make a patch release?

@jgreer
Copy link
Contributor

jgreer commented Sep 5, 2019

Fixed in #34

@jgreer jgreer closed this as completed Sep 5, 2019
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

Successfully merging a pull request may close this issue.

5 participants