TsgcWebSocketHTTPServer › イベント › 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;