TsgcWebSocketHTTPServer | HTTP-serververzoeken

Gebruik OnCommandGet om HTTP-clientverzoeken te verwerken. Gebruik de volgende parameters:

 

 

 

 


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

Gebruik deze gebeurtenis om het HTTP-antwoord aan te passen. Als u bijvoorbeeld wilt dat sommige eindpunten een autorisatieschema gebruiken terwijl andere zonder autorisatie toegankelijk zijn, gebruik dan de opties-parameter om dit toe te staan of uit te schakelen. Hieronder is een voorbeeld waarbij Basic autorisatie is ingeschakeld, maar wanneer een gebruiker het eindpunt /public aanvraagt, is autorisatie niet vereist.

 


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