TsgcHTTP3Server › Methods › SendResponse

SendResponse Method

Sends an HTTP/3 response (HEADERS and DATA frames) on a request stream.

Syntax

procedure SendResponse(const aQUICConn: TsgcQUICServerConnection; aStreamId: Int64; const aResponse: TsgcHTTP3Response); virtual;

Parameters

NameTypeDescription
aQUICConnconst TsgcQUICServerConnectionQUIC connection the response is written to. Nothing is sent when the connection is not one the HTTP/3 layer knows about.
aStreamIdInt64Identifier of the request stream the response belongs to. The response is written to that specific QUIC stream when the transport tracks it, otherwise to the connection's default stream.
aResponseconst TsgcHTTP3ResponseResponse to send. Set StatusCode, ContentType, optional Headers and the Data body before calling. See OnH3Request for how a response is built.

Remarks

In the normal request flow you do not call SendResponse. The server creates a TsgcHTTP3Response with StatusCode preset to 200, raises OnH3Request so the application can fill it, and sends it automatically when the handler returns. Calling SendResponse from inside OnH3Request would send a second response on the same stream. The method is exposed for advanced scenarios in which a response has to be produced outside that flow.

SendResponse QPACK-encodes the response header section into a HEADERS frame, appends a DATA frame when the response carries a body and writes both on the request stream. It composes the header section for you:

Two classes of header are dropped rather than sent, because RFC 9114 forbids them on the wire: pseudo-headers, that is any entry whose name starts with :, and the connection-specific headers connection, keep-alive, proxy-connection, transfer-encoding and upgrade. Set the status through StatusCode rather than by adding a :status entry yourself.

A response to a HEAD request is sent as a header section only. The DATA frame is suppressed even when aResponse.Data is set, as RFC 9114 section 4.1.1 requires, so a HEAD handler may fill the body exactly like a GET handler and let the server strip it.

Before the HEADERS frame goes out, any pending QPACK encoder-stream instructions produced while encoding this response are flushed on the server's QPACK encoder stream, so a client that decodes with the dynamic table can resolve the references.

.NET difference. The .NET implementation declares SendResponse with a connection id string instead of a connection object, and the method is currently a no-op, so no response is written. The HTTP/3 framing and QPACK layer does exist in .NET, and the server uses it for the SETTINGS handshake and for Extended CONNECT / WebTransport, but SendResponse was never wired to it: the method body ignores its arguments and returns. Use the Delphi/C++Builder implementation to send HTTP/3 responses.

Example


oResponse := TsgcHTTP3Response.Create;
try
  oResponse.StatusCode := 200;
  oResponse.ContentType := 'text/plain';
  // custom headers use name=value
  oResponse.Headers.Add('cache-control=no-store');
  oResponse.Data := TEncoding.UTF8.GetBytes('Hello HTTP/3');
  oServer.SendResponse(aConnection, aStreamId, oResponse);
finally
  oResponse.Free;
end;

Back to Methods