TsgcWebSocketLoadBalancerServer › 事件 › OnBeforeSendServerBinding
在负载均衡器将后端服务器绑定信息(主机、端口、协议)发送给新接受的下游客户端之前触发。
property OnBeforeSendServerBinding: TsgcWSLBBeforeSendServerHostEvent;
// TsgcWSLBBeforeSendServerHostEvent = procedure(Connection: TsgcWSConnection; var Binding: TsgcWSLoadBalancerServerBinding) of object
—
OnBeforeSendServerBinding 在负载均衡器为传入客户端连接选取后端服务器之后、将选定的绑定 URL 返回给客户端之前触发。Binding 参数公开将发送回客户端的主机、端口和协议;可修改它以覆盖公共地址(例如,当客户端必须通过反向代理或不同于后端自身注册的公共 IP 访问后端时,重写主机)。典型用途包括为特定客户端 IP 调整绑定、注入粘性会话目标,或根据请求强制特定协议(ws 与 wss)。保留 Binding 不变以使用由所配置 LoadBalancing 算法计算的值。
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;