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;
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;