Use OnCommandGet to handle HTTP client requests. Use the following parameters:
void OnCommandGet(TIdContext *AContext, TIdHTTPRequestInfo *ARequestInfo,
TIdHTTPResponseInfo *AResponseInfo)
{
if (ARequestInfo->Document == "/")
{
AResponseInfo->ContentText = "<html><head><title>Test Page</title></head><body></body></html>";
AResponseInfo->ContentType = "text/html";
AResponseInfo->ResponseNo = 200;
}
}
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.
void __fastcall TForm1::OnBeforeCommand(TsgcWSConnection* aConnection, TIdHTTPRequestInfo* ARequestInfo, TIdHTTPResponseInfo* AResponseInfo, TsgcHTTPCommandOptions &aOptions)
{
if (ARequestInfo->Document == "/public")
aOptions << hcoAuthorizedBasic;
}