IPWorks WebSockets 2020 Delphi Edition

Questions / Feedback?

WebSocketOpenRequest Event

Fired when a client attempts to open a WebSocket.

Syntax

type TWebSocketOpenRequestEvent = procedure (
  Sender: TObject;
  ConnectionId: Integer;
  const RequestURI: String;
  const HostHeader: String;
  const OriginHeader: String;
  var SubProtocols: String;
  const Extensions: String;
  const RequestHeaders: String;
  var StatusCode: Integer;
  var ResponseHeaders: String;
  var ForwardHost: String;
  var ForwardPort: Integer
) of Object;

property OnWebSocketOpenRequest: TWebSocketOpenRequestEvent read FOnWebSocketOpenRequest write FOnWebSocketOpenRequest;

Remarks

This event fires when a client connects. It provides an opportunity to inspect the WebSocket request and either accept or reject the connection attempt.

By default, the component will accept the connection. You do not need to set anything to accept the connection. The component will return a StatusCode of 101 to the connecting client and the request will proceed as normal. To reject a connection, set StatusCode to an HTTP error code, such as 401.

ConnectionId identifies the connecting client.

RequestURI provides the URI requested by the connecting client. This may be used to implement logic to select appropriate SubProtocols or determine if the connection should be accepted based on access restrictions to the URI.

HostHeader holds the value of the Host header sent by the client.

OriginHeader holds the value of the Origin header sent by the client.

SubProtocols holds a comma separated list of subprotocols sent by the client (if any). Set SubProtocols to the selected value from the list sent by the client. The component will return this value to the client as the subprotocol the server has selected.

Extensions provides a list of extensions supported by the client.

RequestHeaders contains the HTTP headers sent in the request by the connecting client.

StatusCode determines success or failure. The value 101 (default) indicates success. This may be set to any HTTP status code. For instance a value of 401 indicates an authorization failure.

ResponseHeaders may be set to include additional headers in the response. This is typically used when rejecting a request. For instance when StatusCode is set to 401 you might set ResponseHeaders to "WWW-Authenticate: Basic realm="Secure Realm"" to request authorization from the connecting client.

ForwardHost may be set to override the value specified in DefaultForwardHost.

ForwardPort may be set to override the value specified in DefaultForwardPort.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks WebSockets 2020 Delphi Edition - Version 20.0 [Build 8155]