TsgcWebSocketHTTPServer › Eventi › OnBeforeCommand
Si attiva prima di OnCommandGet o OnCommandOther in modo che la richiesta possa essere filtrata, autorizzata o interrotta con una risposta 401.
property OnBeforeCommand: TsgcWSOnBeforeCommand;
// TsgcWSOnBeforeCommand = procedure(const aConnection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var aOptions: TsgcHTTPCommandOptions) of object
—
OnBeforeCommand viene eseguito per ogni richiesta HTTP prima che il server la instradi a OnCommandGet o OnCommandOther. Esamini ARequestInfo (Document, Params, Headers, RemoteIP...) per decidere come gestire la richiesta e assegni di conseguenza aOptions. Includa hcoUnauthorized per rifiutare immediatamente la richiesta con una risposta 401 (utile per proteggere un endpoint senza dover scrivere alcuna risposta), includa hcoAuthorizedBasic per forzare l'autenticazione Basic, oppure lasci il set vuoto per consentire l'esecuzione dei normali gestori di comandi. L'evento è il posto consigliato per combinare endpoint pubblici e autenticati sullo stesso server.
procedure OnBeforeCommand(const aConnection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo; var aOptions: TsgcHTTPCommandOptions);
begin
if aRequestInfo.Document = '/public' then
aOptions := [hcoAuthorizedBasic];
end;