TsgcWebSocketHTTPServer › Events › OnCommandOther
Fires when the HTTP server receives a method other than GET, POST or HEAD (PUT, DELETE, OPTIONS, PATCH...).
public event TIdHTTPCommandEventHandler OnCommandOther;
// delegate void TIdHTTPCommandEventHandler(TIdContext AContext, TIdHTTPRequestInfo ARequestInfo, TIdHTTPResponseInfo AResponseInfo)
—
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.
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;
}
}