TsgcWebSocketLoadBalancerServerEvents › OnLoadBalancerHTTPRequest

OnLoadBalancerHTTPRequest Event

Fires for each incoming HTTP request received by the load balancer before it is forwarded to the selected backend server.

Syntax

property OnLoadBalancerHTTPRequest: TsgcWSLBHTTPRequestEvent;
// TsgcWSLBHTTPRequestEvent = procedure(Sender: TObject; Connection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; aForward: TsgcWSServerForwardHTTP) of object

Default Value

Remarks

OnLoadBalancerHTTPRequest is raised for every HTTP request accepted by the load balancer (when LoadBalancer.Protocols.HTTP is True) immediately before it is forwarded to a backend server. ARequestInfo exposes the incoming request (Document, Params, RawHeaders, ContentType, PostStream) and aForward carries the forwarding plan: its Host, Port and SSL properties can be rewritten to target a different backend, a different URL path (aForward.Document), or to toggle TLS. Set aForward.Handled := True to skip forwarding entirely and answer the client yourself through Connection. Typical uses are custom routing rules, request rewriting, header injection, or in-process responses for health endpoints.

Example


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;

Back to Events