TsgcWebSocketHTTPServer › Events › OnHTTP2BeforeAsyncRequest
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.
public event TsgcWSOnBeforeHttp2AsyncRequestHandler OnHTTP2BeforeAsyncRequest;
// delegate void TsgcWSOnBeforeHttp2AsyncRequestHandler(TObject Sender, TsgcWSConnection Connection, TIdHTTPRequestInfo ARequestInfo, out bool Async)
—
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.
void OnHTTP2BeforeAsyncRequest(object Sender, TsgcWSConnection Connection,
TIdHTTPRequestInfo ARequestInfo, ref bool Async)
{
if (ARequestInfo.Document == "/fast-request")
Async = false;
}