TsgcHTTP3Server › 이벤트 › OnH3Request
완전한 HTTP/3 요청이 수신될 때 발생하여 애플리케이션이 응답을 채울 수 있습니다.
property OnH3Request: TsgcHTTP3RequestEvent;
// TsgcHTTP3RequestEvent = procedure(Sender: TObject; const aConnection: TsgcQUICServerConnection; const aRequest: TsgcHTTP3Request; const aResponse: TsgcHTTP3Response) of object
—
| Name | Type | 설명 |
|---|---|---|
aConnection | const TsgcQUICServerConnection | 요청이 도착한 QUIC 연결(PeerIP, PeerPort 및 연결 상태를 노출함). |
aRequest | const TsgcHTTP3Request | 수신된 요청: Method, Path, Host, Scheme, Headers 및 Data 본문. |
aResponse | const TsgcHTTP3Response | 채울 응답: StatusCode, ContentType, 선택적 Headers 및 Data 본문을 설정합니다. |
OnH3Request는 서버가 완전한 HTTP/3 요청(요청 헤더와, POST, PUT, PATCH처럼 본문을 전달하는 메서드의 경우 본문 포함)을 수신하면 발생합니다. 서버는 이벤트를 발생시키기 전에 aResponse 객체를 생성하고 StatusCode를 200으로 미리 설정하므로, 빈 200만 반환하면 되는 핸들러는 이를 그대로 둘 수 있습니다. 필요에 따라 aResponse.StatusCode, aResponse.ContentType, aResponse.Headers 및 aResponse.Data를 채우십시오. 핸들러가 반환되면 서버는 헤더를 QPACK으로 인코딩하고 요청 스트림에서 응답을 자동으로 보냅니다. 이 이벤트 내부에서 SendResponse를 호출할 필요는 없습니다. aRequest.Path와 aRequest.Method를 검사하여 요청을 라우팅하십시오.
procedure OnH3RequestEvent(Sender: TObject; const aConnection:
TsgcQUICServerConnection; const aRequest: TsgcHTTP3Request;
const aResponse: TsgcHTTP3Response);
begin
if aRequest.Path = '/hello' then
begin
aResponse.StatusCode := 200;
aResponse.ContentType := 'text/plain';
aResponse.Data := TEncoding.UTF8.GetBytes('Hello HTTP/3');
end
else
aResponse.StatusCode := 404;
end;