TsgcHTTP3Server › Olaylar › OnH3Request

OnH3Request Olay

Tam bir HTTP/3 isteği alındığında, uygulamanın yanıtı doldurabilmesi için tetiklenir.

Sözdizimi

property OnH3Request: TsgcHTTP3RequestEvent;
// TsgcHTTP3RequestEvent = procedure(Sender: TObject; const aConnection: TsgcQUICServerConnection; const aRequest: TsgcHTTP3Request; const aResponse: TsgcHTTP3Response) of object

Varsayılan Değer

—

Parametreler

NameTypeAçıklama
aConnectionconst TsgcQUICServerConnectionİsteğin geldiği QUIC bağlantısı (PeerIP, PeerPort ve bağlantı durumunu gösterir).
aRequestconst TsgcHTTP3RequestAlınan istek: Method, Path, Host, Scheme, Headers ve Data gövdesi.
aResponseconst TsgcHTTP3ResponseDoldurulacak yanıt: StatusCode, ContentType, isteğe bağlı Headers ve Data gövdesini ayarlayın.

Remarks

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.

Örnek


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;

Olaylara Dön