TsgcHTTP3Server › 方法 › SendResponse
在请求流上发送 HTTP/3 响应(HEADERS 和 DATA 帧)。
procedure SendResponse(const aQUICConn: TsgcQUICServerConnection; aStreamId: Int64; const aResponse: TsgcHTTP3Response);
| 名称 | 类型 | 描述 |
|---|---|---|
aQUICConn | const TsgcQUICServerConnection | 响应写入的 QUIC 连接。 |
aStreamId | Int64 | 响应所属请求流的标识符。 |
aResponse | const TsgcHTTP3Response | 要发送的响应。调用前请设置 StatusCode、ContentType、可选的 Headers 以及 Data 正文。 |
SendResponse 将响应标头 QPACK 编码为 HEADERS 帧,当响应包含正文时追加 DATA 帧,并将两者通过 QUIC 写入请求流。状态码在 :status 伪标头中发送,当存在正文时自动添加 content-length 标头。
在正常请求流程中,无需调用 SendResponse:服务器创建一个 TsgcHTTP3Response(StatusCode 默认为 200),触发 OnH3Request 以便应用程序填写,然后自动发送。SendResponse 适用于需要在该流程之外生成响应的高级场景,并由 SendPush 内部使用。
oResponse := TsgcHTTP3Response.Create;
try
oResponse.StatusCode := 200;
oResponse.ContentType := 'text/plain';
oResponse.Data := TEncoding.UTF8.GetBytes('Hello HTTP/3');
oServer.SendResponse(aConnection, aStreamId, oResponse);
finally
oResponse.Free;
end;