IPWorks WebSockets 2020 macOS Edition

Questions / Feedback?

WebSocketOpenRequest Event

Fired when a client attempts to open a WebSocket.

Syntax

func onWebSocketOpenRequest(connectionId: Int32, requestURI: String, hostHeader: String, originHeader: String, subProtocols: inout String, extensions: String, requestHeaders: String, statusCode: inout Int32, responseHeaders: inout String, forwardHost: inout String, forwardPort: inout Int32)

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 class will accept the connection. You do not need to set anything to accept the connection. The class 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 class 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) 2021 /n software inc. - All rights reserved.
IPWorks WebSockets 2020 macOS Edition - Version 20.0 [Build 7941]