Search code examples
http2

How to make http2 requests with persistent connection ? (Any language)


How connect to https://api.push.apple.com using http2 with persistent connection ?

Persistent connection is to avoid rapid connection and disconnection:

APNs treats rapid connection and disconnection as a denial-of-service attack

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html

Is writing a client in c using https://nghttp2.org the only solution?

(If that question should be ask in another StackExchange website, please do tell me)


Solution

  • Non-persistent connections are a relic of the past. They were used in HTTP/1.0, but HTTP/1.1 already moved to a model where the connections were persistent by default, and HTTP/2 (also being multiplexed) continues on that model of connections being persistent by default.

    Independently on the language you are using to develop your applications, any HTTP/2 compliant client will, by default, use persistent connections.

    You only need to use the HTTP/2 client library in a way that you don't explicitly close the connection after every request you make. Typically these libraries employ a connection pool that keeps the connections open, typically until an idle timeout fires.

    When your application makes HTTP requests, the library will pick an open connection and send the request. When the response arrives the library will not close the connection but instead put it back into the pool for the next usage.

    Just study how the library you want to use allows you to make multiple requests without closing the connection.