TsgcWebSocketHTTPServerZdarzenia › OnCommandOther

OnCommandOther Event

Wywoływane, gdy serwer HTTP odbiera metodę inną niż GET, POST lub HEAD (PUT, DELETE, OPTIONS, PATCH...).

Składnia

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

Wartość domyślna

Uwagi

Zdarzenie OnCommandOther jest wywoływane dla metod HTTP innych niż GET, POST i HEAD (PUT, DELETE, OPTIONS, PATCH, TRACE itd.). Należy sprawdzić ARequestInfo.Command, aby ustalić użyty czasownik, a ARequestInfo.Document wskazuje docelowy URI; należy wypełnić AResponseInfo.ContentText/ContentStream, ContentType i ResponseNo analogicznie jak w OnCommandGet. Obsługa tego zdarzenia to typowy sposób implementacji punktów końcowych REST przyjmujących czasowniki inne niż GET/POST; należy go używać razem z OnBeforeCommand, gdy żądanie wymaga również weryfikacji autoryzacji.

Przykład


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;

Powrót do Zdarzeń