TsgcHTTP3Client › Events › OnHTTP3BeforeRequest

OnHTTP3BeforeRequest Event

Fires before a request is sent, allowing the header list to be inspected or modified.

Syntax

TsgcHTTP3BeforeRequestEvent = procedure(Sender: TObject;

  var Headers: TStringList) of object;



property OnHTTP3BeforeRequest: TsgcHTTP3BeforeRequestEvent

  read FOnHTTP3BeforeRequest write FOnHTTP3BeforeRequest;

Parameters

NameTypeDescription
SenderTObjectThe TsgcHTTP3Client instance that raised the event.
Headersvar TStringListThe full header list about to be encoded, pseudo-headers included, as Name: Value lines. Modify it in place to add, change or remove headers.

Remarks

OnHTTP3BeforeRequest fires for every request, just after the client has built the header list and before it is QPACK-encoded and sent. The list is passed by reference and is fully mutable, which makes this the single hook for anything header-related that has no dedicated property.

The usual reason to handle it is authentication: add an authorization header carrying a bearer token or Basic credentials. It is equally suited to cookies, correlation IDs, API keys and any custom header your API expects.

The list contains the HTTP/3 pseudo-headers :method, :scheme, :authority and :path as well as the ordinary ones. Pseudo-headers must stay at the front of the section and must not be duplicated, so append your own headers rather than inserting at the top, and do not remove the pseudo-headers.

Header names in HTTP/3 must be lowercase (RFC 9114 Section 4.2). An uppercase name is a malformed request and the server will reject it.

The event fires on the thread that is sending the request, which for an Async verb is the background worker thread.

Example



procedure TfrmMain.OnBeforeRequestEvent(Sender: TObject;

  var Headers: TStringList);

begin

  Headers.Add('authorization: Bearer ' + vToken);

  Headers.Add('x-request-id: ' + vRequestId);

end;

Back to Events