Search code examples
apple-push-notificationslibcurlbackwards-compatibilityhttp2

Must I use HTTP/2.0 to send Apple Push Notifications? May I use libcurl?


This question, as you may have inferred from the title, is really two questions in one.

First Question: Must I use HTTP/2.0 to send Apple Push Notifications?

On the APNs Provider API documentation provided by Apple, the opening paragraphs specify:

The provider API is based on the HTTP/2 network protocol.

There are several other references to HTTP/2.0 throughout the documentation. However I don't see (which is not to say it's not there) anything specifying that HTTP/2.0 must be used. Does this mean that I am allowed to use any HTTP version? Or am I in fact constrained to HTTP/2.0?

I am very familiar with HTTP/1.1 but I know almost nothing about HTTP/2.0, thus if I am able to use my old familiar protocol I would prefer that.

Second Question (predicated on first question): May I use libcurl with APNs?

This question is only relevant given an affirmative answer to the first question. If it's not true that I must use HTTP/2.0 with APNs then I already know that I can use libcurl.

I will be sending many APNs from an already busy server and I would prefer to do it natively - therefore I plan to use libcurl if possible. However I understand that libcurl is somewhat limited when it comes to HTTP/2.0.

The main problem is that when libcurl makes an HTTP/2.0 connection, it actually starts with an HTTP/1.1 request that includes an upgrade header, and then waits for a 101 Switching Protocols status line. Is this behavior supported with APNs? Or must I try to use something like nghttp2?

I have found that nghttp2 is somewhat complex and very poorly documented at the moment. I'm worried that if I can't use libcurl I might end up having to implement HTTP/2.0 on my own using sockets (which would be THE WORST).

Any help is appreciated for either question! Thank you, everybody!


Solution

  • OK after a good deal of time I finally found the answer. Yes, HTTP/2 is required to use APNS.

    It comes down to a single line in the APNS docs that says

    APNs requires the use of HPACK (header compression for HTTP/2), which prevents repeated header keys and values.

    which would imply that HTTP/2 is a required part of the protocol.