TsgcHTTP3Server › Events › OnWebTransportSession
Fires when a peer requests a WebTransport session through an Extended CONNECT, so the session can be accepted or rejected.
property OnWebTransportSession: TsgcHTTP3WebTransportSessionEvent;
// TsgcHTTP3WebTransportSessionEvent = procedure(Sender: TObject; const aConnection: TsgcQUICServerConnection; const aSession: TsgcWebTransportSession; var aAccept: Boolean) of object
—
| Name | Type | Description |
|---|---|---|
Sender | TObject | The TsgcHTTP3Server instance that raised the event. |
aConnection | const TsgcQUICServerConnection | QUIC connection the session is being negotiated on. |
aSession | const TsgcWebTransportSession | Session being negotiated. Its SessionId is the id of the CONNECT stream. Assign its OnStream, OnDatagram and OnClose handlers here, before accepting, so no early event is missed. |
aAccept | var Boolean | Accept flag. It arrives as True, so a session is accepted by default. Set it to False to reject the session. |
OnWebTransportSession is raised when a client opens a WebTransport session over HTTP/3, that is, when it sends an Extended CONNECT request (RFC 9220) whose :method is CONNECT and whose :protocol pseudo-header is webtransport. Such a request establishes a session rather than asking for a resource, so it is never routed to OnH3Request.
The event is the accept or reject decision point, and the outcome is decided by aAccept:
| aAccept | What the server does |
|---|---|
True (the value it arrives with) | Replies :status=200 on the CONNECT stream, keeps that stream open for the lifetime of the session and registers the session so its streams and datagrams are routed to it. |
False | Replies :status=404 and discards the session object. No further event fires for it. |
Sessions are accepted by default. Leaving the handler unassigned, or returning from it without touching aAccept, accepts the session. Assign the handler and set aAccept := False to apply authentication or routing rules.
The event only fires when WebTransport is enabled, which means H3Settings.Settings.WebTransportMaxSessions is greater than zero. That setting is also what makes the server advertise SETTINGS_ENABLE_CONNECT_PROTOCOL, SETTINGS_H3_DATAGRAM and SETTINGS_WEBTRANSPORT_MAX_SESSIONS to clients, so leaving it at its default of 0 disables WebTransport entirely and no Extended CONNECT for it will ever arrive.
Note that WebTransport streams work, while WebTransport datagrams cannot be carried on this transport, because the QUIC engine in OpenSSL does not implement the RFC 9221 DATAGRAM extension. Sending one raises TsgcQUICException instead of discarding the payload. See SendDatagram for the details.
The event is raised on the server's background listener thread, so it must not touch the UI directly.
OnWebTransportSession is compiled only when the SGC_WEBTRANSPORT conditional define is enabled.
oServer.H3Settings.Settings.WebTransportMaxSessions := 16; // enables WebTransport
oServer.OnWebTransportSession := OnWebTransportSessionEvent;
procedure OnWebTransportSessionEvent(Sender: TObject; const aConnection:
TsgcQUICServerConnection; const aSession: TsgcWebTransportSession;
var aAccept: Boolean);
begin
// reject everything that does not come from the local network
if Copy(aConnection.PeerIP, 1, 8) <> '192.168.' then
begin
aAccept := False;
Exit;
end;
// wire the session events BEFORE accepting
aSession.OnStream := OnWTStreamEvent;
aSession.OnClose := OnWTCloseEvent;
Log('WebTransport session ' + IntToStr(aSession.SessionId) + ' accepted');
end;