Use HTTP/3 in your C#/.NET 7/8 application

Let’s talk about HTTP/3. It’s enabled by default in .NET 8 and supported in .NET 7 via the kestrel web server.

HTTP/3 changes a lot of what you’ve known about web application protocols: it is secure by including TLS 1.3 in it’s stack and supports fast binary streaming by utilizing UDP as base protocol instead of TCP. You can understand it’s impact even better when you compare it to HTTP/1.1 and HTTP/2.

HTTP/1.1 was a simple text-based protocol based on the IP/TCP stack. It had no intrinsic security features, contained a header representing alone the message content, and could only be used by a simple, non-multiplexed request/response model. However, this simplicity also comes with a price when seen from todays requirements: it’s insecure, it wastes a lot of bandwidth by repeating its header and not allowing binary content, and it does not fit todays fluent UI concepts.

HTTP/2 came about 18 years later, which alone shows the success of HTTP/1.1 simplicity. However, the changing landscape of the web also showed its deficiencies. Thus HTTP/2 added support to handle multiple message streams over a single connection, header compression (HPACK), binary data frames, and the ability to push data from the server to the client without a request from the client. Again, the changing landscape of the web by mobile devices and streaming applications brought this model to it’s limits, as HTTP/2 is still based on IP/TCP, and TCP is inherently a protocol to guarantee the order of the packages, which in unreliable mobile connections combined with streaming of binary data blocks usage for real-time use cases.

HTTP/3 is the up to-date protocol of the HTTP family. Its stack is based on IP/UDP/TLS 1.3. It’s a pure binary protocol and the use of UDP solves the content-blocking issues which arose by TCP. It also improves the header compression (QPACK), and the use of TLS 1.3 as mandatory stack element also adds encryption by default. HTTP/3 is enabled as default protocol for web applications in .NET and will be the future of a web focusing on mobile devices instead of static computer networks.

Here’s an example for a short demo application in .NET 7. You can simply test it by using Wireshark which already supports HTTP/3.

using System.Net;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Server.Kestrel.Core;

var builder = WebHost.CreateDefaultBuilder(args);
builder.UseKestrel(options =>
{
    options.Listen(
        IPAddress.Any,
        1977, 
        listenOptions =>
        {
            listenOptions.Protocols = HttpProtocols.Http3;
        });
});
builder.UseStartup<WebStartup>();

Happy coding 🚀! If you like my post follow me on LinkedIn 🔔!