通过nghttp2使用cURL和HTTP \ 2支持连接到Apple的APNS

时间:2016-02-15 18:11:59

标签: linux curl docker apple-push-notifications nghttp2

我试图通过跟随this tutorial来编译具有HTTP / 2支持的cURL。我使用Docker并且我的应用程序基于使用Debian的official PHP Docker image,尽管我在Vagrant内运行的Ubuntu计算机中产生了同样的问题VM。

起初似乎没有问题。确实,运行curl --version会显示我所期望的一切:

curl 7.47.1 (x86_64-pc-linux-gnu) libcurl/7.47.1 OpenSSL/1.0.1k zlib/1.2.8 libidn/1.29 libssh2/1.4.3 nghttp2/1.7.1 librtmp/2.3
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: IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets 

另外,我可以很好地连接到https://nghttp2.org

curl --http2 -I https://nghttp2.org
HTTP/2.0 200
date:Mon, 15 Feb 2016 18:02:34 GMT
content-type:text/html
content-length:6680
last-modified:Thu, 11 Feb 2016 14:29:49 GMT
etag:"56bc9add-1a18"
link:</stylesheets/screen.css>; rel=preload; as=stylesheet
accept-ranges:bytes
x-backend-header-rtt:0.000581
server:nghttpx nghttp2/1.8.0-DEV
via:1.1 nghttpx
strict-transport-security:max-age=31536000
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
x-content-type-options:nosniff

当尝试连接Apple最近重新启动的APNS Provider API时,问题就开始出现了,现在它在HTTP / 2上运行。

我已经通过我的Mac上的Homebrew安装了curl(使用--with-nghttp2),我可以得到以下(预期)响应:

curl -d 'Hello' --http2 https://api.push.apple.com/3/device/test
{"reason":"Forbidden"}

但是,如果我尝试从Docker镜像中运行相同的命令,我会得到:

curl -d 'Hello' --http2 https://api.push.apple.com/3/device/test
?@@?HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 504f5354202f332f6465766963652f746573742048545450

我不确定为什么这些问题似乎与Apple的服务有关,以及需要采取哪些措施来纠正这种情况。

任何帮助都非常赞赏!

2 个答案:

答案 0 :(得分:0)

对于将来看到这一点的人,我最终解决了这个问题,答案是Server Fault

答案 1 :(得分:0)

问题在于,OpenSSL / 1.0.1k没有ALPN协议。

Apple要求它,而https://nghttp2.org对NPN感到满意。

因此,要解决此问题,请使OpenSSL / 1.0.2正常工作,并且您已经完成了设置。