TsgcWebSocketLoadBalancerServerEvents › OnHandshake

OnHandshake Event

Fires after the load balancer validates an incoming WebSocket handshake and before the HTTP response is returned.

Syntax

property OnHandshake: TsgcWSHandshakeEvent;
// TsgcWSHandshakeEvent = procedure(Connection: TsgcWSConnection; var Headers: TStringList) of object

Default Value

Remarks

OnHandshake is inherited from the HTTP server and is raised when the incoming HTTP Upgrade request has been parsed and is about to be answered. The incoming request headers are available through the HeadersRequest property of the connection (cast to TsgcWSConnectionServer); the Headers list you receive contains the response lines that will be sent to the peer and can be augmented with custom headers. The standard WebSocket headers are already present and must not be duplicated. The event fires both for downstream clients and for backend servers that register through the load balancer, so check Connection.URL if you need to distinguish the two paths.

Example


procedure OnHandshake(Connection: TsgcWSConnection; var Headers: TStringList);
begin
  Headers.Add('X-LoadBalancer: sgcWebSockets');
end;

Back to Events