1 //------------------------------------------------------------------------------
2 // <copyright file="HttpCacheParams.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
8 * Cache Vary class. Wraps Vary header
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>Indicates that a cache should contain multiple
22 /// representations for a particular Uri. This class is an encapsulation that
23 /// provides a rich, type-safe way to set the Vary header.</para>
25 public sealed class HttpCacheVaryByParams {
26 HttpDictionary _parameters;
31 public HttpCacheVaryByParams() {
35 internal void Reset() {
43 /// Set the Parameters in Cache Vary
45 /// <param name="parameters"></param>
46 public void SetParams(string[] parameters) {
50 if (parameters != null) {
52 if (parameters[0].Length == 0) {
53 Debug.Assert(parameters.Length == 1, "parameters.Length == 1");
57 else if (parameters[0].Equals("*")) {
58 Debug.Assert(parameters.Length == 1, "parameters.Length == 1");
63 _parameters = new HttpDictionary();
64 for (i = 0, n = parameters.Length; i < n; i++) {
65 _parameters.SetValue(parameters[i], parameters[i]);
71 internal bool IsModified() {
75 internal bool AcceptsParams() {
76 return _ignoreParams == 1 || _paramsStar || _parameters != null;
80 /// Get the Parameters in Cache Vary
82 /// <returns></returns>
83 public string[] GetParams() {
88 if (_ignoreParams == 1) {
89 s = new string[1] {string.Empty};
91 else if (_paramsStar) {
92 s = new string[1] {"*"};
94 else if (_parameters != null) {
97 for (i = 0; i < n; i++) {
98 item = _parameters.GetValue(i);
107 for (i = 0; i < n; i++) {
108 item = _parameters.GetValue(i);
110 s[j] = (string) item;
115 Debug.Assert(j == c, "j == c");
123 // Public methods and properties
128 /// <para> Default property.
129 /// Indexed property indicating that a cache should (or should not) vary according
130 /// to a custom header.</para>
132 public bool this[String header]
135 if (header == null) {
136 throw new ArgumentNullException("header");
139 if (header.Length == 0) {
140 return _ignoreParams == 1;
143 return _paramsStar ||
144 (_parameters != null && _parameters.GetValue(header) != null);
149 if (header == null) {
150 throw new ArgumentNullException("header");
153 if (header.Length == 0) {
154 IgnoreParams = value;
157 * Since adding a Vary parameter is more restrictive, we don't
158 * want components to be able to set a Vary parameter to false
159 * if another component has set it to true.
164 if (header.Equals("*")) {
169 // set value to header if true or null if false
171 if (_parameters == null) {
172 _parameters = new HttpDictionary();
175 _parameters.SetValue(header, header);
183 public bool IgnoreParams {
185 return _ignoreParams == 1;
189 // Don't ignore if params have been added
190 if (_paramsStar || _parameters != null) {
194 if (_ignoreParams == -1 || _ignoreParams == 1) {
195 _ignoreParams = value ? 1 : 0;
201 internal bool IsVaryByStar {