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

public event TsgcWSOnBeforeHttp2AsyncRequestHandler OnHTTP2BeforeAsyncRequest;
// delegate void TsgcWSOnBeforeHttp2AsyncRequestHandler(TObject Sender, TsgcWSConnection Connection, TIdHTTPRequestInfo ARequestInfo, out bool Async)

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


void OnHTTP2BeforeAsyncRequest(object Sender, TsgcWSConnection Connection,
  TIdHTTPRequestInfo ARequestInfo, ref bool Async)
{
  if (ARequestInfo.Document == "/fast-request")
    Async = false;
}

Back to Events