Merge pull request #3622 from rolfbjarne/remove-stray-file
[mono.git] / mcs / class / System.Web / System.Web / HttpCachePolicy.cs
index dc4b3fd634d1db231249c2ef42dd11f701e3cfc2..4f9ddcda64181589b222cc9bad99f45628431763 100644 (file)
@@ -28,6 +28,7 @@
 //
 
 using System.Collections;
+using System.Collections.Specialized;
 using System.ComponentModel;
 using System.Globalization;
 using System.IO;
@@ -38,31 +39,15 @@ using System.Web.Util;
 
 namespace System.Web
 {
-       class CacheabilityUpdatedEventArgs : EventArgs
-       {
-               public readonly HttpCacheability Cacheability;
-
-               public CacheabilityUpdatedEventArgs (HttpCacheability cacheability)
-               {
-                       Cacheability = cacheability;
-               }
-       }
-       
-       internal delegate void CacheabilityUpdatedCallback (object sender, CacheabilityUpdatedEventArgs args);
-       
        // CAS - no InheritanceDemand here as the class is sealed
        [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public sealed class HttpCachePolicy
        {
-               static readonly object cacheabilityUpdatedEvent = new object ();
-               
                internal HttpCachePolicy ()
                {
                }
 
-#if NET_2_0
                HttpCacheVaryByContentEncodings vary_by_content_encodings = new HttpCacheVaryByContentEncodings ();
-#endif
                HttpCacheVaryByHeaders vary_by_headers = new HttpCacheVaryByHeaders ();
                HttpCacheVaryByParams vary_by_params = new HttpCacheVaryByParams ();
                ArrayList validation_callbacks;
@@ -95,22 +80,11 @@ namespace System.Web
                bool set_no_store;
                bool set_no_transform;
                bool valid_until_expires;
-
-               // always false in 1.x
                bool omit_vary_star;
-
-               EventHandlerList events = new EventHandlerList ();
-
-               internal event CacheabilityUpdatedCallback CacheabilityUpdated {
-                       add { events.AddHandler (cacheabilityUpdatedEvent, value); }
-                       remove { events.RemoveHandler (cacheabilityUpdatedEvent, value); }
-               }
-
-#if NET_2_0
+               
                public HttpCacheVaryByContentEncodings VaryByContentEncodings {
                        get { return vary_by_content_encodings; }
                }
-#endif
 
                public HttpCacheVaryByHeaders VaryByHeaders {
                        get { return vary_by_headers; }
@@ -141,7 +115,6 @@ namespace System.Web
                        get { return validation_callbacks; }
                }
 
-               // always false in 1.x
                internal bool OmitVaryStar {
                        get { return omit_vary_star; }
                }
@@ -192,9 +165,6 @@ namespace System.Web
                                return;
 
                        Cacheability = cacheability;
-                       CacheabilityUpdatedCallback eh = events [cacheabilityUpdatedEvent] as CacheabilityUpdatedCallback;
-                       if (eh != null)
-                               eh (this, new CacheabilityUpdatedEventArgs (cacheability));
                }
 
                public void SetCacheability (HttpCacheability cacheability, string field)
@@ -295,6 +265,7 @@ namespace System.Web
                                return;
 
                        ProxyMaxAge = delta;
+                       HaveProxyMaxAge = true;
                }
 
                public void SetRevalidation (HttpCacheRevalidation revalidation)
@@ -339,7 +310,7 @@ namespace System.Web
                                allow_response_in_browser_history = allow;
                }
 
-               internal void SetHeaders (HttpResponse response, ArrayList headers)
+               internal void SetHeaders (HttpResponse response, NameValueCollection headers)
                {
                        bool noCache = false;
                        string cc = null;
@@ -365,16 +336,16 @@ namespace System.Web
                        if (noCache) {
                                response.CacheControl = cc;
                                if (!allow_response_in_browser_history) {
-                                       headers.Add (new UnknownResponseHeader ("Expires", "-1"));
-                                       headers.Add (new UnknownResponseHeader ("Pragma", "no-cache"));
+                                       headers.Add ("Expires", "-1");
+                                       headers.Add ("Pragma", "no-cache");
                                }
                        } else {
-                               if (MaxAge.TotalSeconds != 0)
+                               if (HaveMaxAge)
                                        cc = String.Concat (cc, ", max-age=", ((long) MaxAge.TotalSeconds).ToString ());
 
                                if (have_expire_date) {
                                        string expires = TimeUtil.ToUtcTimeString (expire_date);
-                                       headers.Add (new UnknownResponseHeader ("Expires", expires));
+                                       headers.Add ("Expires", expires);
                                }
                        }
 
@@ -382,23 +353,27 @@ namespace System.Web
                                cc = String.Concat (cc, ", no-store");
                        if (set_no_transform)
                                cc = String.Concat (cc, ", no-transform");
-
-                       headers.Add (new UnknownResponseHeader ("Cache-Control", cc));
+                       if (cache_extension != null && cache_extension.Length > 0) {
+                               if (!String.IsNullOrEmpty (cc))
+                                       cc = String.Concat (cc, ", ");
+                               cc = String.Concat (cc, cache_extension.ToString ());
+                       }
+                       
+                       headers.Add ("Cache-Control", cc);
 
                        if (last_modified_from_file_dependencies || etag_from_file_dependencies)
                                HeadersFromFileDependencies (response);
 
                        if (etag != null)
-                               headers.Add (new UnknownResponseHeader ("ETag", etag));
+                               headers.Add ("ETag", etag);
 
                        if (have_last_modified)
-                               headers.Add (new UnknownResponseHeader ("Last-Modified",
-                                                            TimeUtil.ToUtcTimeString (last_modified)));
+                               headers.Add ("Last-Modified", TimeUtil.ToUtcTimeString (last_modified));
 
                        if (!vary_by_params.IgnoreParams) {
-                               BaseResponseHeader vb = vary_by_params.GetResponseHeader ();
+                               string vb = vary_by_params.GetResponseHeaderValue ();
                                if (vb != null)
-                                       headers.Add (vb);
+                                       headers.Add ("Vary", vb);
                        }
                }
 
@@ -441,11 +416,9 @@ namespace System.Web
                                etag = etagsb.ToString ();
                }
 
-#if NET_2_0
                public void SetOmitVaryStar (bool omit)
                {
                        omit_vary_star = omit;
                }
-#endif
        }
 }