TsgcWebSocketHTTPServer › Eventi › OnCommandOther
Generato quando il server HTTP riceve un metodo diverso da GET, POST o HEAD (PUT, DELETE, OPTIONS, PATCH...).
property OnCommandOther: TIdHTTPCommandEvent;
// TIdHTTPCommandEvent = procedure(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo) of object
—
OnCommandOther viene generato per i metodi HTTP che non sono GET, POST o HEAD (PUT, DELETE, OPTIONS, PATCH, TRACE...). Ispezionare ARequestInfo.Command per individuare il verbo utilizzato e ARequestInfo.Document per l'URI di destinazione; compilare AResponseInfo.ContentText/ContentStream, ContentType e ResponseNo come in OnCommandGet. La gestione di questo evento è il modo consueto per implementare endpoint REST che accettano verbi oltre a GET/POST; utilizzarlo insieme a OnBeforeCommand quando la richiesta richiede anche una verifica dell'autorizzazione.
procedure OnCommandOther(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
begin
if SameText(ARequestInfo.Command, 'OPTIONS') then
begin
AResponseInfo.CustomHeaders.Add('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
AResponseInfo.ResponseNo := 204;
end;
end;