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.
ServerName to the name in the certificate - see Download a page over HTTPS.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;
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.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.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.
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.
TsmHTTPSClient · TsmHTTPSv2 · TsmHTTPSv3 · StreamSec.Mobile.HTTPSClient · StreamSec.Http.Client · StreamSec.Mobile.HTTPS · StreamSec.Mobile.HTTPSv3