TsgcWebSocketHTTPServer › Events › OnBeforeCommand
Fires before OnCommandGet or OnCommandOther so the request can be screened, authorized, or short-circuited with a 401 response.
public event TsgcWSOnBeforeCommandHandler OnBeforeCommand;
// delegate void TsgcWSOnBeforeCommandHandler(TsgcWSConnection aConnection, TIdHTTPRequestInfo ARequestInfo, TIdHTTPResponseInfo AResponseInfo, out TsgcHTTPCommandOptions aOptions)
—
OnBeforeCommand runs for every HTTP request before the server dispatches it to OnCommandGet or OnCommandOther. Inspect ARequestInfo (Document, Params, Headers, RemoteIP...) to decide how the request must be handled and assign aOptions accordingly. Include hcoUnauthorized to reject the request immediately with a 401 response (useful to gate an endpoint without writing any response yourself), include hcoAuthorizedBasic to force Basic authentication, or leave the set empty to let the normal command handlers run. The event is the recommended place to mix public and authenticated endpoints on the same server.
public void OnBeforeCommand(TsgcWSConnection aConnection, TIdHTTPRequestInfo ARequestInfo,
TIdHTTPResponseInfo AResponseInfo, ref TsgcHTTPCommandOptions aOptions)
{
if (ARequestInfo.Document == "/public")
aOptions = TsgcHTTPCommandOptions.hcoAuthorizedBasic;
}