TsgcWebSocketHTTPServerEventi › OnCommandOther

OnCommandOther Evento

Generato quando il server HTTP riceve un metodo diverso da GET, POST o HEAD (PUT, DELETE, OPTIONS, PATCH...).

Sintassi

property OnCommandOther: TIdHTTPCommandEvent;
// TIdHTTPCommandEvent = procedure(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo) of object

Valore predefinito

Note

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.

Esempio


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;

Torna agli Eventi