TsgcWebSocketLoadBalancerServer › Events › OnBeforeSendServerBinding
Fires before the load balancer sends a backend server binding (host, port, protocol) to a newly accepted downstream client.
property OnBeforeSendServerBinding: TsgcWSLBBeforeSendServerHostEvent;
// TsgcWSLBBeforeSendServerHostEvent = procedure(Connection: TsgcWSConnection; var Binding: TsgcWSLoadBalancerServerBinding) of object
—
OnBeforeSendServerBinding is raised after the load balancer picks a backend server for an incoming client connection and before the selected binding URL is returned to the client. The Binding parameter exposes the host, port and protocol that will be sent back; modify it to override the public address (for example to rewrite the host when the client must reach the backend through a reverse proxy or a different public IP than the one registered by the backend itself). Typical uses are tweaking the binding for specific client IPs, injecting a sticky-session target, or forcing a particular protocol (ws vs wss) based on the request. Leave the Binding unchanged to keep the value computed by the configured LoadBalancing algorithm.
procedure OnBeforeSendServerBinding(Connection: TsgcWSConnection;
var Binding: TsgcWSLoadBalancerServerBinding);
begin
// force secure WebSocket scheme when the client connected over TLS
if Connection.IsSSL then
Binding.Protocol := 'wss';
end;