TsgcWebSocketHTTPServer이벤트 › OnCommandOther

OnCommandOther 이벤트

HTTP 서버가 GET, POST 또는 HEAD 이외의 메서드(PUT, DELETE, OPTIONS, PATCH...)를 수신할 때 발생합니다.

구문

__property TIdHTTPCommandEvent OnCommandOther;
// typedef void __fastcall (__closure *TIdHTTPCommandEvent)(TIdContext * AContext, TIdHTTPRequestInfo * ARequestInfo, TIdHTTPResponseInfo * AResponseInfo);

기본값

설명

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와 함께 사용하십시오.

예제


void OnCommandOther(TIdContext *AContext, TIdHTTPRequestInfo *ARequestInfo,
  TIdHTTPResponseInfo *AResponseInfo)
{
  if (SameText(ARequestInfo->Command, "OPTIONS"))
  {
    AResponseInfo->CustomHeaders->Add("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
    AResponseInfo->ResponseNo = 204;
  }
}

이벤트로 돌아가기