TsgcWebSocketHTTPServer | Richieste HTTP Server

Utilizzare OnCommandGet per gestire le richieste client HTTP. Utilizzare i seguenti parametri:

 

 

 

 


procedure OnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; 
  AResponseInfo: TIdHTTPResponseInfo);
begin
  if ARequestInfo.Document = '/' then
  begin
    AResponseInfo.ContentText := '<html><head><title>Test Page</title></head><body></body></html>';
    AResponseInfo.ContentType := 'text/html';
    AResponseInfo.ResponseNo := 200;
  end;
end;

 

OnBeforeCommand

Utilizzare questo evento per personalizzare la risposta HTTP. Ad esempio, se si desidera che alcuni endpoint utilizzino uno schema di autorizzazione mentre altri sono accessibili senza autorizzazione, utilizzare il parametro options per abilitarlo o disabilitarlo. Di seguito è riportato un esempio in cui l'autorizzazione Basic è abilitata, ma quando un utente richiede l'endpoint /public, l'autorizzazione non è richiesta.

 


procedure OnBeforeCommand(const aConnection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var aOptions: TsgcHTTPCommandOptions);
begin
  if aRequestInfo.Document = '/public' then
    aOptions := [hcoAuthorizedBasic];
end;