TsgcWebSocketLoadBalancerServer › Eventi › OnLoadBalancerHTTPRequest
Si attiva per ogni richiesta HTTP in ingresso ricevuta dal load balancer prima che venga inoltrata al server backend selezionato.
property OnLoadBalancerHTTPRequest: TsgcWSLBHTTPRequestEvent;
// TsgcWSLBHTTPRequestEvent = procedure(Sender: TObject; Connection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; aForward: TsgcWSServerForwardHTTP) of object
—
OnLoadBalancerHTTPRequest viene generato per ogni richiesta HTTP accettata dal load balancer (quando LoadBalancer.Protocols.HTTP è True) immediatamente prima che venga inoltrata a un server backend. ARequestInfo espone la richiesta in arrivo (Document, Params, RawHeaders, ContentType, PostStream) e aForward contiene il piano di inoltro: le sue proprietà Host, Port e SSL possono essere riscritte per puntare a un backend diverso, a un percorso URL diverso (aForward.Document) o per attivare/disattivare TLS. Impostare aForward.Handled := True per saltare l'inoltro e rispondere direttamente al client tramite Connection. Usi tipici: regole di routing personalizzate, riscrittura delle richieste, iniezione di intestazioni o risposte in-process per endpoint di health check.
procedure OnLoadBalancerHTTPRequest(Sender: TObject; Connection: TsgcWSConnection;
ARequestInfo: TIdHTTPRequestInfo; aForward: TsgcWSServerForwardHTTP);
begin
// route /api/* to a different backend
if StartsText('/api', ARequestInfo.Document) then
begin
aForward.Host := '10.0.0.10';
aForward.Port := 9000;
end;
end;