Normalize line endings.
[mono.git] / mcs / class / System.Web / System.Web / HttpCacheVaryByParams.cs
1 //
2 // System.Web.HttpVaryByParams.cs 
3 //
4 // Author:
5 //      Chris Toshok (toshok@novell.com)
6 //
7
8 //
9 // Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Collections;
32 using System.Security.Permissions;
33 using System.Text;
34
35 namespace System.Web
36 {
37
38         // CAS - no InheritanceDemand here as the class is sealed
39         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40         public sealed class HttpCacheVaryByParams
41         {
42                 bool ignore_parms;
43                 Hashtable parms;
44
45 #if NET_4_0
46                 public
47 #else
48                 internal
49 #endif
50                 HttpCacheVaryByParams ()
51                 {
52                         /* the parameter names are meant to be case insensitive */
53                         parms = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
54                 }
55
56                 internal string[] GetParamNames ()
57                 {
58                         string[] names;
59
60                         names = new string [parms.Count];
61
62                         parms.Keys.CopyTo (names, 0);
63
64                         return names;
65                 }
66
67                 internal string GetResponseHeaderValue ()
68                 {
69                         StringBuilder builder = new StringBuilder ();
70
71                         foreach (string parm in parms.Keys) {
72                                 builder.Append (parm);
73                                 builder.Append ("; ");
74                         }
75
76                         if (builder.Length == 0)
77                                 return null;
78
79                         return builder.ToString();
80                 }
81
82                 public bool IgnoreParams {
83                         get {
84                                 return ignore_parms;
85                         }
86                         set {
87                                 ignore_parms = value;
88                         }
89                 }
90
91                 public bool this [ string param ] {
92                         get {
93                                 if (param == null)
94                                         throw new ArgumentNullException ();
95
96                                 return parms.Contains (param);
97                         }
98                         set {
99                                 if (param == null)
100                                         throw new ArgumentNullException ();
101
102                                 ignore_parms = false;
103                                 if (value)
104                                         if (!parms.Contains (param))
105                                                 parms.Add (param, true);
106                                 else
107                                         parms.Remove (param);
108                         }
109                 }
110         }
111
112 }