WebSocketOpenRequest Event
Fired when a client attempts to open a WebSocket.
Syntax
public event OnWebSocketOpenRequestHandler OnWebSocketOpenRequest; public delegate void OnWebSocketOpenRequestHandler(object sender, WebsocketproxyWebSocketOpenRequestEventArgs e); public class WebsocketproxyWebSocketOpenRequestEventArgs : EventArgs { public string ConnectionId { get; } public string RequestURI { get; } public string HostHeader { get; } public string OriginHeader { get; } public string SubProtocols { get; set; } public string Extensions { get; } public string RequestHeaders { get; } public int StatusCode { get; set; } public string ResponseHeaders { get; set; } public string ForwardHost { get; set; } public int ForwardPort { get; set; } }
Public Event OnWebSocketOpenRequest As OnWebSocketOpenRequestHandler Public Delegate Sub OnWebSocketOpenRequestHandler(sender As Object, e As WebsocketproxyWebSocketOpenRequestEventArgs) Public Class WebsocketproxyWebSocketOpenRequestEventArgs Inherits EventArgs Public ReadOnly Property ConnectionId As String Public ReadOnly Property RequestURI As String Public ReadOnly Property HostHeader As String Public ReadOnly Property OriginHeader As String Public Property SubProtocols As String Public ReadOnly Property Extensions As String Public ReadOnly Property RequestHeaders As String Public Property StatusCode As Integer Public Property ResponseHeaders As String Public Property ForwardHost As String Public Property ForwardPort As Integer End Class
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.