TsgcWebSocketHTTPServerEvents › OnCommandOther

OnCommandOther Event

Fires when the HTTP server receives a method other than GET, POST or HEAD (PUT, DELETE, OPTIONS, PATCH...).

Syntax

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

Default Value

Remarks

OnCommandOther is raised for HTTP methods that are not GET, POST or HEAD (PUT, DELETE, OPTIONS, PATCH, TRACE...). Inspect ARequestInfo.Command to find out which verb was used and ARequestInfo.Document for the target URI; populate AResponseInfo.ContentText/ContentStream, ContentType and ResponseNo just like in OnCommandGet. Handling this event is the usual way to implement REST endpoints that accept verbs beyond GET/POST; use it together with OnBeforeCommand when the request also needs authorization screening.

Example


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;

Back to Events