TsgcWebSocketHTTPServerEvents › OnHTTP2BeforeAsyncRequest

OnHTTP2BeforeAsyncRequest Event

Fires before an HTTP/2 request is queued so the application can choose whether it runs in the pool of threads or in the connection thread.

Syntax

property OnHTTP2BeforeAsyncRequest: TsgcWSOnBeforeHttp2AsyncRequest;
// TsgcWSOnBeforeHttp2AsyncRequest = procedure(Sender: TObject; Connection: TsgcWSConnection; const ARequestInfo: TIdHTTPRequestInfo; var Async: Boolean) of object

Default Value

Remarks

When HTTP2Options.PoolOfThreads.Enabled is True the server dispatches incoming HTTP/2 requests on a worker pool (HTTP2Options.Threads) to take advantage of HTTP/2 multiplexing. OnHTTP2BeforeAsyncRequest is raised for every request before it is queued: inspect ARequestInfo.Document to decide, and set Async to True (the default) to run in the thread pool or to False to run in the connection thread. Routing short requests to the connection thread avoids the pool overhead while keeping slow requests threaded, which is the recommended fine-tuning strategy.

Example


procedure OnHTTP2BeforeAsyncRequest(Sender: TObject; Connection: TsgcWSConnection;
  const ARequestInfo: TIdHTTPRequestInfo; var Async: Boolean);
begin
  if ARequestInfo.Document = '/fast-request' then
    Async := False;
end;

Back to Events