TsgcWebSocketHTTPServerEvents › OnCommandOther

OnCommandOther 事件

当 HTTP 服务器收到 GET、POST 或 HEAD 以外的方法(PUT、DELETE、OPTIONS、PATCH……)时触发。

语法

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

默认值

备注

OnCommandOther 在非 GET、POST 或 HEAD 的 HTTP 方法(PUT、DELETE、OPTIONS、PATCH、TRACE……)时触发。检查 ARequestInfo.Command 以找出使用的动词,ARequestInfo.Document 为目标 URI;与 OnCommandGet 类似填充 AResponseInfo.ContentText/ContentStream、ContentType 和 ResponseNo。处理此事件是实现接受 GET/POST 以外动词的 REST 端点的常用方式;当请求还需要授权筛查时与 OnBeforeCommand 一起使用。

示例


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;

返回事件