Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http/2 HttpClient and HPACK For APNs

I am writing code to send notifications to the Apple push notification servers (APNs). It says in the documents that it requires HTTP/ HPACK header compression. I found the following code to use HTTP/2 with C# httpclient:

public class Http2CustomHandler : WinHttpHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
    {
        request.Version = new Version("2.0");
        return base.SendAsync(request, cancellationToken);
    }
}

using (var httpClient = new HttpClient(new Http2CustomHandler()))
{

}

Does that compress the headers that I will add to the HttpClient automatically or should I add the header data some other way?

like image 458
John L. Avatar asked Aug 26 '17 13:08

John L.


People also ask

What version of HTTP does the httpclient use?

In 2.1 a new, far faster SocketsHttpClientHandler was added as a default. The new handler doesn't support HTTP/2 yet. The same code will return 1.1 as the protocol version. If the app context switch is set before creating the HttpClient though, HTTP/2 is used. This code will return 2.0. Interestingly, there's no need to specify the HTTP version.

Does hpack match HTTP headers?

Although HPACK does string matching, for the attacker to find the value of a header, they must guess the entire value, instead of a gradual approach that was possible with DEFLATE matching, and was vulnerable to CRIME. The gains HPACK provides for HTTP request headers are more significant than for response headers.

What is this APNs library for?

The focus of this library is to bring enough HTTP/2 functionality to .NET for implementing the APNS (Apple Push Notification Service) provider API over HTTP/2 within PushSharp It's currently not very well tested and lacks some implementation details.

Does Nginx support the full hpack header compression?

This is the HPACK header compression. Current implementation of nginx, as well edge networks and CDNs using it, do not support the full HPACK implementation. We have, however, implemented the full HPACK in nginx, and upstreamed the part that performs Huffman encoding.


1 Answers

Yes it does compress the headers. You don't have to do anything extra.

like image 119
Andrei Avatar answered Oct 22 '22 15:10

Andrei