TsgcWebSocketHTTPServerEvents › OnCommandOther

OnCommandOther Event

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

Syntax

public event TIdHTTPCommandEventHandler OnCommandOther;
// delegate void TIdHTTPCommandEventHandler(TIdContext AContext, TIdHTTPRequestInfo ARequestInfo, TIdHTTPResponseInfo AResponseInfo)

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


void OnCommandOther(TsgcWSConnection Connection, TsgcWSHTTPRequestInfo RequestInfo,
  ref TsgcWSHTTPResponseInfo ResponseInfo)
{
  if (string.Equals(RequestInfo.Command, "OPTIONS", StringComparison.OrdinalIgnoreCase))
  {
    ResponseInfo.CustomHeaders.Add("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
    ResponseInfo.ResponseNo = 204;
  }
}

Back to Events