diff --git a/websocket-sharp/Server/WebSocketBehavior.cs b/websocket-sharp/Server/WebSocketBehavior.cs index c0ea719b..33519aa2 100644 --- a/websocket-sharp/Server/WebSocketBehavior.cs +++ b/websocket-sharp/Server/WebSocketBehavior.cs @@ -47,6 +47,7 @@ namespace WebSocketSharp.Server private WebSocketContext _context; private Func _cookiesValidator; private string _id; + private bool _ignoreExtensions; private Func _originValidator; private string _protocol; private WebSocketSessionManager _sessions; @@ -159,6 +160,24 @@ namespace WebSocketSharp.Server } } + /// + /// Gets or sets a value indicating whether the WebSocket service ignores + /// the Sec-WebSocket-Extensions header included in a connection request. + /// + /// + /// true if the WebSocket service ignores the extensions; otherwise, false. + /// The default value is false. + /// + public bool IgnoreExtensions { + get { + return _ignoreExtensions; + } + + set { + _ignoreExtensions = value; + } + } + /// /// Gets or sets the delegate called to validate the Origin header included in a connection /// request to the WebSocket service. @@ -316,6 +335,7 @@ namespace WebSocketSharp.Server _websocket = context.WebSocket; _websocket.CustomHandshakeRequestChecker = checkIfValidConnectionRequest; + _websocket.IgnoreExtensions = _ignoreExtensions; _websocket.Protocol = _protocol; var waitTime = sessions.WaitTime; diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index b1b85c9c..3b674328 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -86,6 +86,7 @@ namespace WebSocketSharp private const string _guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; private Func _handshakeRequestChecker; + private bool _ignoreExtensions; private volatile Logger _logger; private Queue _messageEventQueue; private uint _nonceCount; @@ -225,6 +226,17 @@ namespace WebSocketSharp } } + // As server + internal bool IgnoreExtensions { + get { + return _ignoreExtensions; + } + + set { + _ignoreExtensions = value; + } + } + internal bool IsConnected { get { return _readyState == WebSocketState.Open || _readyState == WebSocketState.Closing; @@ -577,9 +589,11 @@ namespace WebSocketSharp !_context.SecWebSocketProtocols.Contains (protocol => protocol == _protocol)) _protocol = null; - var extensions = _context.Headers["Sec-WebSocket-Extensions"]; - if (extensions != null && extensions.Length > 0) - processSecWebSocketExtensionsHeader (extensions); + if (!_ignoreExtensions) { + var extensions = _context.Headers["Sec-WebSocket-Extensions"]; + if (extensions != null && extensions.Length > 0) + processSecWebSocketExtensionsHeader (extensions); + } return sendHttpResponse (createHandshakeResponse ()); }