TsgcWebSocketHTTPServer | HTTP 服务器请求

使用 OnCommandGet 处理 HTTP 客户端请求。使用以下参数:

 

 

 

 


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

使用此事件自定义 HTTP 响应。例如,如果您希望某些端点使用授权方案,而其他端点可以在不授权的情况下访问,请使用 options 参数来允许或禁用它。以下示例中,启用了 Authorization Basic,但当用户请求端点 /public 时,不需要授权。

 


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