Beispiel #1
0
        /// <summary>
        /// Creates new instance of <see cref="WebSocketDeflateCompressionProvider"/>
        /// </summary>
        /// <param name="compressionOptions">The compression options.</param>
        /// <param name="sendSegmentSize">The maximum size of single segment which will be sent over the WebSocket connection.</param>
        /// <returns>New instance of <see cref="WebSocketDeflateCompressionProvider"/> or NULL if provided options are not supported.</returns>
        public static WebSocketDeflateCompressionProvider Create(WebSocketDeflateCompressionOptions compressionOptions, int?sendSegmentSize = null)
        {
            if (compressionOptions.ServerMaxWindowBits.HasValue)
            {
                return(null);
            }

            compressionOptions.ClientNoContextTakeover = true;

            return(new WebSocketDeflateCompressionProvider(compressionOptions, sendSegmentSize));
        }
        /// <summary>
        /// Creates new instance of <see cref="WebSocketDeflateCompressionOptions"/> from header value.
        /// </summary>
        /// <param name="headerValue">The header value.</param>
        /// <returns>New instance of <see cref="WebSocketDeflateCompressionOptions"/>.</returns>
        public static WebSocketDeflateCompressionOptions FromHeaderValue(NameValueWithParametersHeaderValue headerValue)
        {
            WebSocketDeflateCompressionOptions compressionOptions = new WebSocketDeflateCompressionOptions();

            foreach (NameValueHeaderValue parameterValue in headerValue.Parameters)
            {
                switch (parameterValue.Name.ToLowerInvariant())
                {
                case SERVER_NO_CONTEXT_TAKEOVER_OPTION:
                    compressionOptions = SetAndEnsureServerNoContextTakeover(compressionOptions);
                    break;

                case CLIENT_NO_CONTEXT_TAKEOVER_OPTION:
                    compressionOptions = SetAndEnsureClientNoContextTakeover(compressionOptions);
                    break;

                case SERVER_MAX_WINDOW_BITS_OPTION:
                    compressionOptions = SetAndEnsureServerMaxWindowBits(compressionOptions, parameterValue.Value);
                    break;

                case CLIENT_MAX_WINDOW_BITS_OPTION:
                    compressionOptions = SetAndEnsureClientMaxWindowBits(compressionOptions, parameterValue.Value);
                    break;

                default:
                    compressionOptions = null;
                    break;
                }

                if (compressionOptions == null)
                {
                    break;
                }
            }

            return(compressionOptions);
        }
Beispiel #3
0
 private WebSocketDeflateCompressionProvider(WebSocketDeflateCompressionOptions compressionOptions, int?sendSegmentSize)
     : base(sendSegmentSize)
 {
     _compressionOptions = compressionOptions;
 }
        private static WebSocketDeflateCompressionOptions SetAndEnsureClientMaxWindowBits(WebSocketDeflateCompressionOptions compressionOptions, string clientMaxWindowBitsValue)
        {
            int clientMaxWindowBits = ClientMaxWindowBitsWithoutValue;

            if (compressionOptions.ClientMaxWindowBits.HasValue || (!String.IsNullOrEmpty(clientMaxWindowBitsValue) && TryParseMaxWindowBits(clientMaxWindowBitsValue, out clientMaxWindowBits)))
            {
                compressionOptions = null;
            }
            else
            {
                compressionOptions.ClientMaxWindowBits = clientMaxWindowBits;
            }

            return(compressionOptions);
        }
        private static WebSocketDeflateCompressionOptions SetAndEnsureServerMaxWindowBits(WebSocketDeflateCompressionOptions compressionOptions, string serverMaxWindowBitsValue)
        {
            int serverMaxWindowBits;

            if (compressionOptions.ServerMaxWindowBits.HasValue || !TryParseMaxWindowBits(serverMaxWindowBitsValue, out serverMaxWindowBits))
            {
                compressionOptions = null;
            }
            else
            {
                compressionOptions.ServerMaxWindowBits = serverMaxWindowBits;
            }

            return(compressionOptions);
        }
        private static WebSocketDeflateCompressionOptions SetAndEnsureClientNoContextTakeover(WebSocketDeflateCompressionOptions compressionOptions)
        {
            if (compressionOptions.ClientNoContextTakeover)
            {
                compressionOptions = null;
            }
            else
            {
                compressionOptions.ClientNoContextTakeover = true;
            }

            return(compressionOptions);
        }