Contents · Forum Home · StreamSec Tools 4.1.5.365 documentation

Use HTTP/2 and HTTP/3

An HTTPS client offers HTTP/2 and HTTP/1.1 over TCP by default. To reach the same service over HTTP/3, enable discovery before connecting. Start with the host, port and trusted roots from Download a page over HTTPS.

The client checks, on every connection, that the server's certificate is issued for the host name it connects to. Give it the DNS name the certificate carries, not the server's IP address: with an address the connection fails although the server's certificate is valid. To connect by address, set ServerName to the name in the certificate - see Download a page over HTTPS.

Make the first request over TCP

uses
  StreamSec.Http.Client, StreamSec.Mobile.HTTPSClient,
  StreamSec.Mobile.HTTPS, StreamSec.Mobile.HTTPSv3;
procedure EnableHttp3Discovery(aClient: TsmCustomHTTPSClient);
begin
  aClient.Protocols := [hcpHttp11, hcpHttp2, hcpHttp3];
end;

function GetUsingProtocol(aClient: TsmCustomHTTPSClient; const aURL: string;
  out aWire: tHttpClientWire): Integer;
var
  lResponse: tHttpResponse;
begin
  lResponse := aClient.Get(aURL);
  try
    Result := lResponse.StatusCode;
    aWire := aClient.Wire;
  finally
    lResponse.Free;
  end;
end;
  1. On a fresh client, call EnableHttp3Discovery and then GetUsingProtocol for a small resource on the origin. The server selects an offered TCP protocol during the TLS handshake. hcwHttp2 means HTTP/2; hcwHttp11 means HTTP/1.1.
  2. If the authenticated response advertises a same-host HTTP/3 endpoint in its Alt-Svc field, make the next request with the same client and origin URL. Once earlier exchanges have released their response bodies, the client can try the advertised UDP port. hcwHttp3 means the request used HTTP/3.
  3. Keep the original host and port in the URL, including a nondefault port. The advertised UDP port changes where the client connects. The certificate must still cover the original DNS name.

With no usable advertisement, or if QUIC setup fails before submission, the request can use TCP. After submission on HTTP/3 the client reports a failure to the application and leaves the decision to retry to the caller. A client configured with HTTP/3 as its only protocol cannot bootstrap.

Advertise an HTTP/3 endpoint you operate

Attach TsmHTTPSv2 to the TCP listener and TsmHTTPSv3 to a TsmAsyncQUICServer serving the same origin and routes. Configure a certificate for the origin on both listeners. Call this before starting them, passing the public origin, for example https://api.example.com:8443.

procedure AdvertiseHttp3(aHttp2: TsmHTTPSv2; aHttp3: TsmHTTPSv3;
  const aOrigin: string);
begin
  aHttp2.AltSvc.Source := aHttp3;
  aHttp2.AltSvc.Origin := aOrigin;
  aHttp2.AltSvc.Enabled := True;
end;

The HTTP/2 server advertises its HTTP/3 companion when that endpoint is ready. If HTTP/1.1 clients should also discover it, assign the same AltSvc settings to the HTTP/1.1 component. When a proxy exposes a different UDP port, set AltSvc.PublicPort to the port clients can reach.

See the HTTPS client notes for discovery and cache lifetime, and the QUIC server notes for setting up the UDP listener.

Reference

TsmHTTPSClient · TsmHTTPSv2 · TsmHTTPSv3 · StreamSec.Mobile.HTTPSClient · StreamSec.Http.Client · StreamSec.Mobile.HTTPS · StreamSec.Mobile.HTTPSv3

Related tasks