TsgcHTTP3Client › Events › OnResponse

OnResponse Event

Fires when a complete HTTP/3 response has been received.

Syntax

TsgcHTTP3ResponseEvent = procedure(Sender: TObject;

  const aResponse: TsgcHTTP3Response) of object;



property OnResponse: TsgcHTTP3ResponseEvent read FOnResponse write FOnResponse;

Parameters

NameTypeDescription
SenderTObjectThe TsgcHTTP3Client instance that raised the event.
aResponseconst TsgcHTTP3ResponseThe response. StatusCode is the HTTP status, Headers the response headers, Data the raw body bytes, ContentType and ContentLength the corresponding header values. Call GetDataAsString to decode the body as text.

Remarks

OnResponse fires once the full response has arrived, meaning the headers and the complete body. It is the main way to read the reply of an asynchronous request such as GetAsync, because those methods return immediately and hand back nothing.

The event also fires for synchronous verbs, which additionally return the body directly, and after a successful ExtendedConnect so the handshake response can be inspected. It does not fire for pushed responses, which are delivered on OnPush, nor for tunnelled bytes, which are delivered on OnTunnelData.

The response object belongs to the client and is only valid inside the handler, so copy anything you need to keep.

Decode the body with GetDataAsString, which honours the charset in the content-type header and falls back to UTF-8.

The event fires on the thread that drove the request. For a synchronous verb that is the thread that made the call; for an asynchronous verb it is the background worker thread created by the Async method. Synchronise before touching VCL or FMX controls from the handler.

Example



procedure TfrmMain.OnResponseEvent(Sender: TObject;

  const aResponse: TsgcHTTP3Response);

begin

  if aResponse.StatusCode = 200 then

    Log(aResponse.GetDataAsString)

  else

    Log('HTTP %d', [aResponse.StatusCode]);

end;

Back to Events