Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientCompressionHandler" /> class.
        /// </summary>
        /// <param name="innerHandler">The inner handler.</param>
        /// <param name="contentSizeThreshold">The content size threshold before compressing.</param>
        /// <param name="compressors">The compressors.</param>
        public ClientCompressionHandler(HttpMessageHandler innerHandler, int contentSizeThreshold, params ICompressor[] compressors)
        {
            if (innerHandler != null)
            {
                this.InnerHandler = innerHandler;
            }

            this.Compressors          = compressors;
            this.contentSizeThreshold = contentSizeThreshold;

            this.httpContentOperations = new HttpContentOperations();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerCompressionHandler" /> class.
        /// </summary>
        /// <param name="innerHandler">The inner handler.</param>
        /// <param name="contentSizeThreshold">The content size threshold before compressing.</param>
        /// <param name="compressors">The compressors.</param>
        public ServerCompressionHandler(HttpMessageHandler innerHandler, int contentSizeThreshold, params ICompressor[] compressors)
        {
            if (innerHandler != null)
            {
                this.InnerHandler = innerHandler;
            }
            
            this.Compressors = compressors;
            this.contentSizeThreshold = contentSizeThreshold;

            this.httpContentOperations = new HttpContentOperations();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerCompressionHandler" /> class.
        /// </summary>
        /// <param name="innerHandler">The inner handler.</param>
        /// <param name="contentSizeThreshold">The content size threshold before compressing.</param>
        /// <param name="enableCompression">Custom delegate to enable or disable compression.</param>
        /// <param name="compressors">The compressors.</param>
        public ServerCompressionHandler(HttpMessageHandler innerHandler, int contentSizeThreshold, Predicate <HttpRequestMessage> enableCompression, params ICompressor[] compressors)
        {
            if (innerHandler != null)
            {
                this.InnerHandler = innerHandler;
            }

            this.Compressors           = compressors;
            this.contentSizeThreshold  = contentSizeThreshold;
            this.httpContentOperations = new HttpContentOperations();

            this.enableCompression = enableCompression ?? (x =>
            {
                if (!x.Properties.ContainsKey("compression:Enable"))
                {
                    return(true);
                }

                bool enable;
                bool.TryParse(x.Properties["compression:Enable"].ToString(), out enable);

                return(enable);
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerCompressionHandler" /> class.
        /// </summary>
        /// <param name="innerHandler">The inner handler.</param>
        /// <param name="contentSizeThreshold">The content size threshold before compressing.</param>
        /// <param name="enableCompression">Custom delegate to enable or disable compression.</param>
        /// <param name="compressors">The compressors.</param>
        public ServerCompressionHandler(HttpMessageHandler innerHandler, int contentSizeThreshold, Predicate<HttpRequestMessage> enableCompression, params ICompressor[] compressors)
        {
            if (innerHandler != null)
            {
                this.InnerHandler = innerHandler;
            }

            this.Compressors = compressors;
            this.contentSizeThreshold = contentSizeThreshold;
            this.httpContentOperations = new HttpContentOperations();

            this.enableCompression = enableCompression ?? (x =>
                {
                    if (!x.Properties.ContainsKey("compression:Enable"))
                    {
                        return true;
                    }

                    bool enable;
                    bool.TryParse(x.Properties["compression:Enable"].ToString(), out enable);

                    return enable;
                });
        }