2 // System.Web.Caching.CachedVaryBy
5 // Jackson Harper (jackson@ximian.com)
7 // (C) 2003 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.Globalization;
35 using System.Collections;
37 namespace System.Web.Caching {
39 internal class CachedVaryBy {
41 private string[] prms;
42 private string[] headers;
43 private string custom;
45 private ArrayList item_list;
46 private bool wildCardParams;
48 internal CachedVaryBy (HttpCachePolicy policy, string key)
50 prms = policy.VaryByParams.GetParamNames ();
51 headers = policy.VaryByHeaders.GetHeaderNames ();
52 custom = policy.GetVaryByCustom ();
54 item_list = new ArrayList ();
55 wildCardParams = policy.VaryByParams ["*"];
58 internal ArrayList ItemList {
59 get { return item_list; }
66 internal string CreateKey (string file_path, HttpContext context)
68 StringBuilder builder = new StringBuilder ();
69 HttpApplication app = context.ApplicationInstance;
70 HttpRequest request = context.Request;
72 builder.Append ("CachedRawResponse\n");
73 builder.Append (file_path);
74 builder.Append ('\n');
75 builder.Append ("METHOD:" + request.HttpMethod);
76 builder.Append ('\n');
79 foreach (string p in request.QueryString) {
80 // FIXME: QueryString might contain a null key if a page gets called like this: page.aspx?arg (w/out the "=")
81 if (p == null) continue;
82 builder.Append ("VPQ:");
83 builder.Append (p.ToLower (CultureInfo.InvariantCulture));
85 builder.Append (request.QueryString [p]);
86 builder.Append ('\n');
88 foreach (string p in request.Form) {
89 // FIXME: can this be null, too?
90 if (p == null) continue;
91 builder.Append ("VPF:");
92 builder.Append (p.ToLower (CultureInfo.InvariantCulture));
94 builder.Append (request.Form [p]);
95 builder.Append ('\n');
97 } else if (prms != null) {
98 for (int i=0; i<prms.Length; i++) {
99 if (request.QueryString [prms [i]] != null) {
100 builder.Append ("VPQ:");
101 builder.Append (prms [i].ToLower (CultureInfo.InvariantCulture));
102 builder.Append ('=');
103 builder.Append (request.QueryString [prms [i]]);
104 builder.Append ('\n');
106 if (request.Form [prms [i]] != null) {
107 builder.Append ("VPF:");
108 builder.Append (prms [i].ToLower (CultureInfo.InvariantCulture));
109 builder.Append ('=');
110 builder.Append (request.Form [prms [i]]);
111 builder.Append ('\n');
116 if (headers != null) {
117 for (int i=0; i<headers.Length; i++) {
118 builder.Append ("VH:");
119 builder.Append (headers [i].ToLower (CultureInfo.InvariantCulture));
120 builder.Append ('=');
121 builder.Append (request.Headers [headers [i]]);
122 builder.Append ('\n');
126 if (custom != null) {
127 string s = app.GetVaryByCustomString (context, custom);
128 builder.Append ("VC:");
129 builder.Append (custom);
130 builder.Append ('=');
131 builder.Append (s != null ? s : "__null__");
132 builder.Append ('\n');
135 return builder.ToString ();