1 //------------------------------------------------------------------------------
2 // <copyright file="HttpCacheVaryByContentEncodings.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
8 * HttpCacheVaryByContentEncodings
10 * Copyright (c) 1998 Microsoft Corporation
13 namespace System.Web {
15 using System.Runtime.InteropServices;
16 using System.Web.Util;
17 using System.Security.Permissions;
21 /// <para>Provides a type-safe way to vary by Content-Encoding.</para>
23 public sealed class HttpCacheVaryByContentEncodings {
24 String[] _contentEncodings;
27 public HttpCacheVaryByContentEncodings() {
31 internal void Reset() {
33 _contentEncodings = null;
37 * Reset based on content encodings.
39 internal void ResetFromContentEncodings(String[] contentEncodings) {
41 if (contentEncodings != null) {
43 _contentEncodings = new String[contentEncodings.Length];
44 for (int i = 0; i < contentEncodings.Length; i++) {
45 _contentEncodings[i] = contentEncodings[i];
50 // the response is not cacheable if we're varying by content encoding
51 // and the content-encoding header is not one of the encodings that we're
53 internal bool IsCacheableEncoding(string coding) {
54 // return true if we are not varying by content encoding.
55 if (_contentEncodings == null) {
59 // return true if there is no Content-Encoding header
64 // return true if the Content-Encoding header is listed
65 for (int i = 0; i < _contentEncodings.Length; i++) {
66 if (_contentEncodings[i] == coding) {
71 // return false if the Content-Encoding header is not listed
75 internal bool IsModified() {
79 internal String[] GetContentEncodings() {
80 return _contentEncodings;
84 // Public methods and properties
89 /// <para> Default property.
90 /// Indexed property indicating that a cache should (or should not) vary according
91 /// to a Content-Encoding.</para>
93 public bool this[String contentEncoding]
96 if (String.IsNullOrEmpty(contentEncoding)) {
97 throw new ArgumentNullException(SR.GetString(SR.Parameter_NullOrEmpty, "contentEncoding"));
99 if (_contentEncodings == null) {
102 for(int i = 0; i < _contentEncodings.Length; i++) {
103 if (_contentEncodings[i] == contentEncoding) {
111 if (String.IsNullOrEmpty(contentEncoding)) {
112 throw new ArgumentNullException(SR.GetString(SR.Parameter_NullOrEmpty, "contentEncoding"));
115 // if someone enabled it, don't allow someone else to disable it.
121 if (_contentEncodings != null) {
122 string[] contentEncodings = new String[_contentEncodings.Length + 1];
123 for (int i = 0; i < _contentEncodings.Length; i++) {
124 contentEncodings[i] = _contentEncodings[i];
126 contentEncodings[contentEncodings.Length - 1] = contentEncoding;
127 _contentEncodings = contentEncodings;
130 _contentEncodings = new String[1];
131 _contentEncodings[0] = contentEncoding;