TsgcHTTP3Server › Events › OnWebTransportSession

OnWebTransportSession Event

Fires when a peer requests a WebTransport session through an Extended CONNECT, so the session can be accepted or rejected.

Syntax

property OnWebTransportSession: TsgcHTTP3WebTransportSessionEvent;
// TsgcHTTP3WebTransportSessionEvent = procedure(Sender: TObject; const aConnection: TsgcQUICServerConnection; const aSession: TsgcWebTransportSession; var aAccept: Boolean) of object

Default Value

—

Parameters

NameTypeDescription
SenderTObjectThe TsgcHTTP3Server instance that raised the event.
aConnectionconst TsgcQUICServerConnectionQUIC connection the session is being negotiated on.
aSessionconst TsgcWebTransportSessionSession 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.
aAcceptvar BooleanAccept flag. It arrives as True, so a session is accepted by default. Set it to False to reject the session.

Remarks

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:

aAcceptWhat 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.
FalseReplies :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.

Example


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;

Back to Events