HttpCacheVaryByContentEncodings.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / HttpCacheVaryByContentEncodings.cs / 1 / HttpCacheVaryByContentEncodings.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 * HttpCacheVaryByContentEncodings 
 *
 * Copyright (c) 1998 Microsoft Corporation 
 */

namespace System.Web {
    using System.Text; 
    using System.Runtime.InteropServices;
    using System.Web.Util; 
    using System.Security.Permissions; 

 
    /// 
    ///    Provides a type-safe way to vary by Content-Encoding.
    /// 
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
    public sealed class HttpCacheVaryByContentEncodings {
        String[]        _contentEncodings; 
        bool            _isModified; 

        internal HttpCacheVaryByContentEncodings() { 
            Reset();
        }

        internal void Reset() { 
            _isModified = false;
            _contentEncodings = null; 
        } 

        /* 
         * Reset based on content encodings.
         */
        internal void ResetFromContentEncodings(String[] contentEncodings) {
            Reset(); 
            if (contentEncodings != null) {
                _isModified = true; 
                _contentEncodings = new String[contentEncodings.Length]; 
                for (int i = 0; i < contentEncodings.Length; i++) {
                    _contentEncodings[i] = contentEncodings[i]; 
                }
            }
        }
 
        // the response is not cacheable if we're varying by content encoding
        // and the content-encoding header is not one of the encodings that we're 
        // varying by 
        internal bool IsCacheableEncoding(string coding) {
            // return true if we are not varying by content encoding. 
            if (_contentEncodings == null) {
                return true;
            }
 
            // return true if there is no Content-Encoding header
            if (coding == null) { 
                return true; 
            }
 
            // return true if the Content-Encoding header is listed
            for (int i = 0; i < _contentEncodings.Length; i++) {
                if (_contentEncodings[i] == coding) {
                    return true; 
                }
            } 
 
            // return false if the Content-Encoding header is not listed
            return false; 
        }

        internal bool IsModified() {
            return _isModified; 
        }
 
        internal String[] GetContentEncodings() { 
            return _contentEncodings;
        } 

        //
        // Public methods and properties
        // 

 
        ///  
        ///     Default property.
        ///       Indexed property indicating that a cache should (or should not) vary according 
        ///       to a Content-Encoding.
        /// 
        public bool this[String contentEncoding]
        { 
            get {
                if (String.IsNullOrEmpty(contentEncoding)) { 
                    throw new ArgumentNullException(SR.GetString(SR.Parameter_NullOrEmpty, "contentEncoding")); 
                }
                if (_contentEncodings == null) { 
                    return false;
                }
                for(int i = 0; i < _contentEncodings.Length; i++) {
                    if (_contentEncodings[i] == contentEncoding) { 
                        return true;
                    } 
                } 
                return false;
            } 

            set {
                if (String.IsNullOrEmpty(contentEncoding)) {
                    throw new ArgumentNullException(SR.GetString(SR.Parameter_NullOrEmpty, "contentEncoding")); 
                }
 
                // if someone enabled it, don't allow someone else to disable it. 
                if (!value) {
                    return; 
                }

                _isModified = true;
                if (_contentEncodings != null) { 
                    string[] contentEncodings = new String[_contentEncodings.Length + 1];
                    for (int i = 0; i < _contentEncodings.Length; i++) { 
                        contentEncodings[i] = _contentEncodings[i]; 
                    }
                    contentEncodings[contentEncodings.Length - 1] = contentEncoding; 
                    _contentEncodings = contentEncodings;
                    return;
                }
                _contentEncodings = new String[1]; 
                _contentEncodings[0] = contentEncoding;
            } 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 * HttpCacheVaryByContentEncodings 
 *
 * Copyright (c) 1998 Microsoft Corporation 
 */

namespace System.Web {
    using System.Text; 
    using System.Runtime.InteropServices;
    using System.Web.Util; 
    using System.Security.Permissions; 

 
    /// 
    ///    Provides a type-safe way to vary by Content-Encoding.
    /// 
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
    public sealed class HttpCacheVaryByContentEncodings {
        String[]        _contentEncodings; 
        bool            _isModified; 

        internal HttpCacheVaryByContentEncodings() { 
            Reset();
        }

        internal void Reset() { 
            _isModified = false;
            _contentEncodings = null; 
        } 

        /* 
         * Reset based on content encodings.
         */
        internal void ResetFromContentEncodings(String[] contentEncodings) {
            Reset(); 
            if (contentEncodings != null) {
                _isModified = true; 
                _contentEncodings = new String[contentEncodings.Length]; 
                for (int i = 0; i < contentEncodings.Length; i++) {
                    _contentEncodings[i] = contentEncodings[i]; 
                }
            }
        }
 
        // the response is not cacheable if we're varying by content encoding
        // and the content-encoding header is not one of the encodings that we're 
        // varying by 
        internal bool IsCacheableEncoding(string coding) {
            // return true if we are not varying by content encoding. 
            if (_contentEncodings == null) {
                return true;
            }
 
            // return true if there is no Content-Encoding header
            if (coding == null) { 
                return true; 
            }
 
            // return true if the Content-Encoding header is listed
            for (int i = 0; i < _contentEncodings.Length; i++) {
                if (_contentEncodings[i] == coding) {
                    return true; 
                }
            } 
 
            // return false if the Content-Encoding header is not listed
            return false; 
        }

        internal bool IsModified() {
            return _isModified; 
        }
 
        internal String[] GetContentEncodings() { 
            return _contentEncodings;
        } 

        //
        // Public methods and properties
        // 

 
        ///  
        ///     Default property.
        ///       Indexed property indicating that a cache should (or should not) vary according 
        ///       to a Content-Encoding.
        /// 
        public bool this[String contentEncoding]
        { 
            get {
                if (String.IsNullOrEmpty(contentEncoding)) { 
                    throw new ArgumentNullException(SR.GetString(SR.Parameter_NullOrEmpty, "contentEncoding")); 
                }
                if (_contentEncodings == null) { 
                    return false;
                }
                for(int i = 0; i < _contentEncodings.Length; i++) {
                    if (_contentEncodings[i] == contentEncoding) { 
                        return true;
                    } 
                } 
                return false;
            } 

            set {
                if (String.IsNullOrEmpty(contentEncoding)) {
                    throw new ArgumentNullException(SR.GetString(SR.Parameter_NullOrEmpty, "contentEncoding")); 
                }
 
                // if someone enabled it, don't allow someone else to disable it. 
                if (!value) {
                    return; 
                }

                _isModified = true;
                if (_contentEncodings != null) { 
                    string[] contentEncodings = new String[_contentEncodings.Length + 1];
                    for (int i = 0; i < _contentEncodings.Length; i++) { 
                        contentEncodings[i] = _contentEncodings[i]; 
                    }
                    contentEncodings[contentEncodings.Length - 1] = contentEncoding; 
                    _contentEncodings = contentEncodings;
                    return;
                }
                _contentEncodings = new String[1]; 
                _contentEncodings[0] = contentEncoding;
            } 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK