public void NormalData() { var handshaker = new PerMessageDeflateClientExtensionHandshaker(); WebSocketExtensionData data = handshaker.NewRequestData(); Assert.Equal(PerMessageDeflateExtension, data.Name); Assert.Equal(ZlibCodecFactory.IsSupportingWindowSizeAndMemLevel ? 1 : 0, data.Parameters.Count); }
public void CustomHandshake() { var handshaker = new PerMessageDeflateServerExtensionHandshaker(6, true, 10, true, true); var parameters = new Dictionary <string, string> { { ClientMaxWindow, null }, { ServerMaxWindow, "12" }, { ClientNoContext, null }, { ServerNoContext, null } }; IWebSocketServerExtension extension = handshaker.HandshakeExtension( new WebSocketExtensionData(PerMessageDeflateExtension, parameters)); Assert.NotNull(extension); Assert.Equal(WebSocketRsv.Rsv1, extension.Rsv); Assert.IsType <PerMessageDeflateDecoder>(extension.NewExtensionDecoder()); Assert.IsType <PerMessageDeflateEncoder>(extension.NewExtensionEncoder()); WebSocketExtensionData data = extension.NewReponseData(); Assert.Equal(PerMessageDeflateExtension, data.Name); Assert.Contains(ClientMaxWindow, data.Parameters.Keys); Assert.Equal("10", data.Parameters[ClientMaxWindow]); Assert.Contains(ServerMaxWindow, data.Parameters.Keys); Assert.Equal("12", data.Parameters[ServerMaxWindow]); parameters = new Dictionary <string, string> { { ServerMaxWindow, "12" }, { ServerNoContext, null } }; extension = handshaker.HandshakeExtension( new WebSocketExtensionData(PerMessageDeflateExtension, parameters)); Assert.NotNull(extension); Assert.Equal(WebSocketRsv.Rsv1, extension.Rsv); Assert.IsType <PerMessageDeflateDecoder>(extension.NewExtensionDecoder()); Assert.IsType <PerMessageDeflateEncoder>(extension.NewExtensionEncoder()); data = extension.NewReponseData(); Assert.Equal(PerMessageDeflateExtension, data.Name); Assert.Equal(2, data.Parameters.Count); Assert.Contains(ServerMaxWindow, data.Parameters.Keys); Assert.Equal("12", data.Parameters[ServerMaxWindow]); Assert.Contains(ServerNoContext, data.Parameters.Keys); parameters = new Dictionary <string, string>(); extension = handshaker.HandshakeExtension( new WebSocketExtensionData(PerMessageDeflateExtension, parameters)); Assert.NotNull(extension); data = extension.NewReponseData(); Assert.Equal(PerMessageDeflateExtension, data.Name); Assert.Empty(data.Parameters); }
public void DeflateFrameData() { var handshaker = new DeflateFrameClientExtensionHandshaker(false); WebSocketExtensionData data = handshaker.NewRequestData(); Assert.Equal(DeflateFrameExtension, data.Name); Assert.Empty(data.Parameters); }
public void CustomData() { var handshaker = new PerMessageDeflateClientExtensionHandshaker(6, true, 10, true, true); WebSocketExtensionData data = handshaker.NewRequestData(); Assert.Equal(PerMessageDeflateExtension, data.Name); Assert.Contains(ClientMaxWindow, data.Parameters.Keys); Assert.Contains(ServerMaxWindow, data.Parameters.Keys); Assert.Equal("10", data.Parameters[ServerMaxWindow]); }
public IWebSocketServerExtension HandshakeExtension(WebSocketExtensionData extensionData) { if (!XWebkitDeflateFrameExtension.Equals(extensionData.Name) && !DeflateFrameExtension.Equals(extensionData.Name)) { return(null); } if (extensionData.Parameters.Count == 0) { return(new DeflateFrameServerExtension(this.compressionLevel, extensionData.Name)); } else { return(null); } }
public void NormalHandshake() { var handshaker = new PerMessageDeflateServerExtensionHandshaker(); IWebSocketServerExtension extension = handshaker.HandshakeExtension( new WebSocketExtensionData(PerMessageDeflateExtension, new Dictionary <string, string>())); Assert.NotNull(extension); Assert.Equal(WebSocketRsv.Rsv1, extension.Rsv); Assert.IsType <PerMessageDeflateDecoder>(extension.NewExtensionDecoder()); Assert.IsType <PerMessageDeflateEncoder>(extension.NewExtensionEncoder()); WebSocketExtensionData data = extension.NewReponseData(); Assert.Equal(PerMessageDeflateExtension, data.Name); Assert.Empty(data.Parameters); var parameters = new Dictionary <string, string> { { ClientMaxWindow, null }, { ClientNoContext, null } }; extension = handshaker.HandshakeExtension( new WebSocketExtensionData(PerMessageDeflateExtension, parameters)); Assert.NotNull(extension); Assert.Equal(WebSocketRsv.Rsv1, extension.Rsv); Assert.IsType <PerMessageDeflateDecoder>(extension.NewExtensionDecoder()); Assert.IsType <PerMessageDeflateEncoder>(extension.NewExtensionEncoder()); data = extension.NewReponseData(); Assert.Equal(PerMessageDeflateExtension, data.Name); Assert.Empty(data.Parameters); parameters = new Dictionary <string, string> { { ServerMaxWindow, "12" }, { ServerNoContext, null } }; extension = handshaker.HandshakeExtension( new WebSocketExtensionData(PerMessageDeflateExtension, parameters)); Assert.Null(extension); }
public IWebSocketClientExtension HandshakeExtension(WebSocketExtensionData extensionData) { if ((uint)extensionData.Parameters.Count > 0u) { return(null); } var extensionDataName = extensionData.Name; switch (extensionDataName) { case XWebkitDeflateFrameExtension: case DeflateFrameExtension: return(new DeflateFrameClientExtension(_compressionLevel, _extensionFilterProvider)); default: if (string.Equals(XWebkitDeflateFrameExtension, extensionDataName, StringComparison.OrdinalIgnoreCase) || string.Equals(DeflateFrameExtension, extensionDataName, StringComparison.OrdinalIgnoreCase)) { return(new DeflateFrameClientExtension(_compressionLevel, _extensionFilterProvider)); } return(null); } }
public IWebSocketClientExtension HandshakeExtension(WebSocketExtensionData extensionData) { if (!PerMessageDeflateExtension.Equals(extensionData.Name)) { return(null); } bool succeed = true; int clientWindowSize = MaxWindowSize; int serverWindowSize = MaxWindowSize; bool serverNoContext = false; bool clientNoContext = false; foreach (KeyValuePair <string, string> parameter in extensionData.Parameters) { if (ClientMaxWindow.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // allowed client_window_size_bits if (this.allowClientWindowSize) { clientWindowSize = int.Parse(parameter.Value); } else { succeed = false; } } else if (ServerMaxWindow.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // acknowledged server_window_size_bits serverWindowSize = int.Parse(parameter.Value); if (clientWindowSize > MaxWindowSize || clientWindowSize < MinWindowSize) { succeed = false; } } else if (ClientNoContext.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // allowed client_no_context_takeover if (this.allowClientNoContext) { clientNoContext = true; } else { succeed = false; } } else if (ServerNoContext.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // acknowledged server_no_context_takeover if (this.requestedServerNoContext) { serverNoContext = true; } else { succeed = false; } } else { // unknown parameter succeed = false; } if (!succeed) { break; } } if ((this.requestedServerNoContext && !serverNoContext) || this.requestedServerWindowSize != serverWindowSize) { succeed = false; } if (succeed) { return(new WebSocketPermessageDeflateExtension(serverNoContext, serverWindowSize, clientNoContext, this.compressionLevel)); } else { return(null); } }
public IWebSocketClientExtension HandshakeExtension(WebSocketExtensionData extensionData) { if (!IsPerMessageDeflateExtension(extensionData.Name)) { return(null); } bool succeed = true; int clientWindowSize = MaxWindowSize; int serverWindowSize = MaxWindowSize; bool serverNoContext = false; bool clientNoContext = false; foreach (KeyValuePair <string, string> parameter in extensionData.Parameters) { var parameterKey = parameter.Key; switch (parameterKey) { case ClientMaxWindow: // allowed client_window_size_bits if (_allowClientWindowSize) { clientWindowSize = int.Parse(parameter.Value); } else { succeed = false; } break; case ServerMaxWindow: // acknowledged server_window_size_bits serverWindowSize = int.Parse(parameter.Value); uint uclientWindowSize0 = (uint)clientWindowSize; if (uclientWindowSize0 > (uint)MaxWindowSize || uclientWindowSize0 < (uint)MinWindowSize) { succeed = false; } break; case ClientNoContext: // allowed client_no_context_takeover if (_allowClientNoContext) { clientNoContext = true; } else { succeed = false; } break; case ServerNoContext: // acknowledged server_no_context_takeover if (_requestedServerNoContext) { serverNoContext = true; } else { succeed = false; } break; default: if (string.Equals(ClientMaxWindow, parameterKey, StringComparison.OrdinalIgnoreCase)) { // allowed client_window_size_bits if (_allowClientWindowSize) { clientWindowSize = int.Parse(parameter.Value); } else { succeed = false; } } else if (string.Equals(ServerMaxWindow, parameterKey, StringComparison.OrdinalIgnoreCase)) { // acknowledged server_window_size_bits serverWindowSize = int.Parse(parameter.Value); uint uclientWindowSize = (uint)clientWindowSize; if (uclientWindowSize > (uint)MaxWindowSize || uclientWindowSize < (uint)MinWindowSize) { succeed = false; } } else if (string.Equals(ClientNoContext, parameterKey, StringComparison.OrdinalIgnoreCase)) { // allowed client_no_context_takeover if (_allowClientNoContext) { clientNoContext = true; } else { succeed = false; } } else if (string.Equals(ServerNoContext, parameterKey, StringComparison.OrdinalIgnoreCase)) { // acknowledged server_no_context_takeover if (_requestedServerNoContext) { serverNoContext = true; } else { succeed = false; } } else { // unknown parameter succeed = false; } break; } if (!succeed) { break; } } if ((_requestedServerNoContext && !serverNoContext) || _requestedServerWindowSize != serverWindowSize) { succeed = false; } if (succeed) { return(new WebSocketPermessageDeflateExtension(serverNoContext, serverWindowSize, clientNoContext, clientWindowSize, _compressionLevel, _extensionFilterProvider)); } else { return(null); } }
public IWebSocketServerExtension HandshakeExtension(WebSocketExtensionData extensionData) { if (!PerMessageDeflateExtension.Equals(extensionData.Name)) { return(null); } bool deflateEnabled = true; int clientWindowSize = MaxWindowSize; int serverWindowSize = MaxWindowSize; bool serverNoContext = false; bool clientNoContext = false; foreach (KeyValuePair <string, string> parameter in extensionData.Parameters) { if (ClientMaxWindow.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // use preferred clientWindowSize because client is compatible with customization clientWindowSize = this.preferredClientWindowSize; } else if (ServerMaxWindow.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // use provided windowSize if it is allowed if (this.allowServerWindowSize) { serverWindowSize = int.Parse(parameter.Value); if (serverWindowSize > MaxWindowSize || serverWindowSize < MinWindowSize) { deflateEnabled = false; } } else { deflateEnabled = false; } } else if (ClientNoContext.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // use preferred clientNoContext because client is compatible with customization clientNoContext = this.preferredClientNoContext; } else if (ServerNoContext.Equals(parameter.Key, StringComparison.OrdinalIgnoreCase)) { // use server no context if allowed if (this.allowServerNoContext) { serverNoContext = true; } else { deflateEnabled = false; } } else { // unknown parameter deflateEnabled = false; } if (!deflateEnabled) { break; } } if (deflateEnabled) { return(new WebSocketPermessageDeflateExtension(this.compressionLevel, serverNoContext, serverWindowSize, clientNoContext, clientWindowSize)); } else { return(null); } }
public IWebSocketServerExtension HandshakeExtension(WebSocketExtensionData extensionData) { if (!IsPerMessageDeflateExtension(extensionData.Name)) { return(null); } bool deflateEnabled = true; int clientWindowSize = MaxWindowSize; int serverWindowSize = MaxWindowSize; bool serverNoContext = false; bool clientNoContext = false; foreach (KeyValuePair <string, string> parameter in extensionData.Parameters) { var parameterKey = parameter.Key; switch (parameterKey) { case ClientMaxWindow: // use preferred clientWindowSize because client is compatible with customization clientWindowSize = _preferredClientWindowSize; break; case ServerMaxWindow: // use provided windowSize if it is allowed if (_allowServerWindowSize) { serverWindowSize = int.Parse(parameter.Value); uint userverWindowSize = (uint)serverWindowSize; if (userverWindowSize > (uint)MaxWindowSize || userverWindowSize < (uint)MinWindowSize) { deflateEnabled = false; } } else { deflateEnabled = false; } break; case ClientNoContext: // use preferred clientNoContext because client is compatible with customization clientNoContext = _preferredClientNoContext; break; case ServerNoContext: // use server no context if allowed if (_allowServerNoContext) { serverNoContext = true; } else { deflateEnabled = false; } break; default: if (string.Equals(ClientMaxWindow, parameterKey, StringComparison.OrdinalIgnoreCase)) { // use preferred clientWindowSize because client is compatible with customization clientWindowSize = _preferredClientWindowSize; } else if (string.Equals(ServerMaxWindow, parameterKey, StringComparison.OrdinalIgnoreCase)) { // use provided windowSize if it is allowed if (_allowServerWindowSize) { serverWindowSize = int.Parse(parameter.Value); uint userverWindowSize = (uint)serverWindowSize; if (userverWindowSize > (uint)MaxWindowSize || userverWindowSize < (uint)MinWindowSize) { deflateEnabled = false; } } else { deflateEnabled = false; } } else if (string.Equals(ClientNoContext, parameterKey, StringComparison.OrdinalIgnoreCase)) { // use preferred clientNoContext because client is compatible with customization clientNoContext = _preferredClientNoContext; } else if (string.Equals(ServerNoContext, parameterKey, StringComparison.OrdinalIgnoreCase)) { // use server no context if allowed if (_allowServerNoContext) { serverNoContext = true; } else { deflateEnabled = false; } } else { // unknown parameter deflateEnabled = false; } break; } if (!deflateEnabled) { break; } } if (deflateEnabled) { return(new WebSocketPermessageDeflateExtension(_compressionLevel, serverNoContext, serverWindowSize, clientNoContext, clientWindowSize, _extensionFilterProvider)); } else { return(null); } }