Yesterday's post introduced the raw QUIC transport in sgcQUIC. Today we look at the layer that sits on top of it: HTTP/3 (RFC 9114). Two components, TsgcHTTP3Client and TsgcHTTP3Server, bring the modern web transport to Delphi, C++ Builder and .NET.
HTTP/3 keeps the request and response semantics you already know from HTTP/1.1 and HTTP/2, but runs them over QUIC instead of TCP. Headers are compressed with QPACK (RFC 9204), and because QUIC multiplexes streams independently, a lost packet no longer stalls every request on the connection.
The HTTP/3 Client
Connect to a host, then call one of the verb methods. Get returns the body as a string, and the full response, including status code and headers, is delivered to OnResponse.
uses
sgcHTTP3_Client;
var
oClient: TsgcHTTP3Client;
vBody: string;
begin
oClient := TsgcHTTP3Client.Create(nil);
oClient.OnResponse := OnResponse;
oClient.OnAltSvc := OnAltSvc;
oClient.Connect('www.example.com', 443);
vBody := oClient.Get('https://www.example.com/');
end;
procedure TForm1.OnResponse(Sender: TObject; aResponse: TsgcHTTP3Response);
begin
Memo1.Lines.Add('status ' + IntToStr(aResponse.StatusCode));
Memo1.Lines.Add(aResponse.GetDataAsString);
end;
Every HTTP verb is available: Get, Head, Post, Put, Delete, Patch, Options, Trace, Connect and Query. Each one has an async counterpart (GetAsync, PostAsync, and so on) that returns at once and reports the result through OnResponse.
QPACK and Alt-Svc
QPACK compresses request and response headers using a dynamic table carried on dedicated encoder and decoder streams. You can tune it through Settings:
oClient.Settings.QPACKMaxTableCapacity := 4096;
oClient.Settings.MaxFieldSectionSize := 65536;
Many servers still answer the first request over HTTP/1.1 or HTTP/2 and advertise HTTP/3 in an Alt-Svc header (RFC 7838). The OnAltSvc event surfaces that advertisement, so a client can discover the HTTP/3 endpoint and upgrade on the next request.
The HTTP/3 Server
The server inherits its QUIC listener and certificate options from the QUIC layer, so it is configured the same way, with a port and a PEM certificate and key. Each request raises OnH3Request, where you fill the response object.
uses
sgcHTTP3_Server;
var
oServer: TsgcHTTP3Server;
begin
oServer := TsgcHTTP3Server.Create(nil);
oServer.Port := 443;
oServer.QUICOptions.SSLOptions.CertFile := 'cert.pem';
oServer.QUICOptions.SSLOptions.KeyFile := 'key.pem';
oServer.OnH3Request := OnH3Request;
oServer.Active := True;
end;
procedure TForm1.OnH3Request(Sender: TObject;
const aConnection: TsgcQUICServerConnection;
const aRequest: TsgcHTTP3Request; const aResponse: TsgcHTTP3Response);
begin
aResponse.StatusCode := 200;
aResponse.ContentType := 'text/plain';
aResponse.Data := TEncoding.UTF8.GetBytes('Hello from HTTP/3');
end;
Server Push, Tunnels and WebTransport
The components implement the wider HTTP/3 feature set as well. A server can push a resource before the client asks for it with PushPromise, and the client receives it through OnPushPromise. Extended CONNECT (RFC 9220) opens tunnels over an HTTP/3 stream, and WebTransport builds on the same mechanism to offer bidirectional streams and datagrams for real-time applications.
Availability
sgcQUIC is a separate package, licensed as an add-on to sgcWebSockets Enterprise, and it includes both the QUIC and the HTTP/3 components. Every license ships with full Pascal source code and one year of updates. The components install on the SGC QUIC palette and support Delphi and C++ Builder 7 through 13, plus a .NET port with the same Tsgc class names.
Download the trial and read the full reference on the sgcQUIC product page.
Questions or feedback? Get in touch, you will get a reply from the people who wrote the code.
