TsgcWebSocketServerEvents › OnHandshake

OnHandshake Event

Fires after the handshake is evaluated on the server side and before the response is sent.

Syntax

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

Default Value

Remarks

OnHandshake is raised on the server immediately after a client's HTTP upgrade request has been parsed and validated, and before the handshake response is written back. The incoming headers sent by the client are available through the HeadersRequest property of the connection (cast to TsgcWSConnectionServer). The Headers parameter is a TStringList containing the response lines that will be returned; add custom lines (for example a vendor-specific header) to include them in the HTTP response. Standard WebSocket headers (Upgrade, Connection, Sec-WebSocket-Accept...) are already populated and should not be duplicated.

Example


procedure OnServerHandshake(Connection: TsgcWSConnection; var Headers: TStringList);
begin
  ShowMessage(TsgcWSConnectionServer(Connection).HeadersRequest.Text);
end;

Back to Events