TsgcWebSocketHTTPServer › Événements › OnCommandOther
Se déclenche lorsque le serveur HTTP reçoit une méthode autre que GET, POST ou HEAD (PUT, DELETE, OPTIONS, PATCH...).
property OnCommandOther: TIdHTTPCommandEvent;
// TIdHTTPCommandEvent = procedure(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo) of object
—
OnCommandOther est déclenché pour les méthodes HTTP autres que GET, POST ou HEAD (PUT, DELETE, OPTIONS, PATCH, TRACE...). Inspectez ARequestInfo.Command pour savoir quel verbe a été utilisé et ARequestInfo.Document pour l'URI cible ; renseignez AResponseInfo.ContentText/ContentStream, ContentType et ResponseNo comme dans OnCommandGet. La gestion de cet événement est la façon habituelle d'implémenter des points de terminaison REST qui acceptent des verbes au-delà de GET/POST ; utilisez-le conjointement avec OnBeforeCommand lorsque la requête nécessite également un filtrage d'autorisation.
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;