Use OnCommandGet to handle HTTP client requests. Use the following 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;
Use this event to customize the HTTP response, example: if you want that some endpoints are using an authorization scheme while others can be accessed without authorization, use the options parameter to allow or disable it. Find below an example when Authorization Basic is enabled but when a user requests the endpoint /public the authorization is not required.
procedure OnBeforeCommand(const aConnection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var aOptions: TsgcHTTPCommandOptions);
begin
if aRequestInfo.Document = '/public' then
aOptions := [hcoAuthorizedBasic];
end;