molnarg / node-http2

An HTTP/2 client and server implementation for node.js
MIT License
1.79k stars 185 forks source link

Binary output when talking to Twitter API #240

Open jsha opened 7 years ago

jsha commented 7 years ago

The Twitter API uses HTTP/2, but trying to access it with node-http2 results in binary output rather than the expected textual output.

Steps to reproduce:

$ node node_modules/http2/example/client.js https://api.twitter.com/robots.txt
x�T�A
�0��}N1�Nhf�u��H�3�LȄ��
                       �����OtSzH��H� _+��J%Z��콪cؐ����k������e��aE��̸o��(�}
                                                                          �t3'�9���������*
$ curl https://api.twitter.com/robots.txt
# Used for Google app indexing. See https://developers.google.com/app-indexing/webmasters/server
User-agent: Googlebot
Disallow:

User-agent: *
Disallow: /
jsha commented 7 years ago

This appears to be related to deflate encoding. Adding code to print the headers shows 'content-encoding': 'deflate',, and piping the output to perl -MCompress::Zlib -e 'undef $/; print uncompress(<>)' results in correct output.

Poking through the source it looks like this library doesn't yet support either gzip or deflate, so it should probably send a blank Accept-Encoding header.