TsgcHTTP3Server › Olaylar › OnH3Request
Tam bir HTTP/3 isteği alındığında, uygulamanın yanıtı doldurabilmesi için tetiklenir.
property OnH3Request: TsgcHTTP3RequestEvent;
// TsgcHTTP3RequestEvent = procedure(Sender: TObject; const aConnection: TsgcQUICServerConnection; const aRequest: TsgcHTTP3Request; const aResponse: TsgcHTTP3Response) of object
—
| Name | Type | Açıklama |
|---|---|---|
aConnection | const TsgcQUICServerConnection | İsteğin geldiği QUIC bağlantısı (PeerIP, PeerPort ve bağlantı durumunu gösterir). |
aRequest | const TsgcHTTP3Request | Alınan istek: Method, Path, Host, Scheme, Headers ve Data gövdesi. |
aResponse | const TsgcHTTP3Response | Doldurulacak yanıt: StatusCode, ContentType, isteğe bağlı Headers ve Data gövdesini ayarlayın. |
OnH3Request, sunucu tam bir HTTP/3 isteği aldıktan sonra tetiklenir (istek başlıkları artı POST, PUT ve PATCH gibi gövde taşıyan yöntemler için gövde). Sunucu, olayı tetiklemeden önce aResponse nesnesini oluşturur ve StatusCode'u 200 olarak ayarlar; bu nedenle yalnızca boş bir 200 döndürmesi gereken bir işleyici bunu değiştirmeden bırakabilir. Gerektiğinde aResponse.StatusCode, aResponse.ContentType, aResponse.Headers ve aResponse.Data'yı doldurun; işleyici döndüğünde sunucu başlıkları QPACK ile kodlar ve yanıtı istek akışında otomatik olarak gönderir. Bu olayın içinden SendResponse çağırmanıza gerek yoktur. İsteği yönlendirmek için aRequest.Path ve aRequest.Method'u inceleyin.
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;