New test.
[mono.git] / mcs / class / System.Web / System.Web / HttpResponse.cs
index bea5e09f0e47d05b9ea8f48411ad3e17fed38276..890078fb4a179bffa4567190965a291a6c06bc51 100644 (file)
@@ -61,7 +61,7 @@ namespace System.Web {
                string charset;
                bool charset_set;
                CachedRawResponse cached_response;
-               string user_cache_control;
+               string user_cache_control = "private";
                string redirect_location;
                
                //
@@ -590,7 +590,9 @@ namespace System.Web {
                                        // If we are not chunked, we need to set "Connection: close".
                                        //
                                        if (use_chunked){
+#if DEBUG
                                                Console.WriteLine ("Setting to close2");
+#endif
                                                write_headers.Add (new KnownResponseHeader (HttpWorkerRequest.HeaderConnection, "close"));
                                        }
                                }
@@ -600,7 +602,9 @@ namespace System.Web {
                                // close at the end.
                                //
                                if (use_chunked){
+#if DEBUG
                                        Console.WriteLine ("Setting to close");
+#endif
                                        write_headers.Add (new KnownResponseHeader (HttpWorkerRequest.HeaderConnection, "close"));
                                }
                        }
@@ -610,8 +614,6 @@ namespace System.Web {
                        //
                        if (cache_policy != null)
                                cache_policy.SetHeaders (this, headers);
-                       else if (user_cache_control != null)
-                               write_headers.Add (new UnknownResponseHeader ("Cache-Control", user_cache_control));
                        else
                                write_headers.Add (new UnknownResponseHeader ("Cache-Control", CacheControl));
                        
@@ -904,6 +906,7 @@ namespace System.Web {
                internal void TransmitFile (string filename, bool final_flush)
                {
                        FileInfo fi = new FileInfo (filename);
+                       using (Stream s = fi.OpenRead ()); // Just check if we can read.
                        output_stream.WriteFile (filename, 0, fi.Length);
                        output_stream.ApplyFilter (final_flush);
                        Flush (final_flush);
@@ -961,34 +964,25 @@ namespace System.Web {
                //
                public string CacheControl {
                        set {
-                               if (String.Compare (value, "public", true, CultureInfo.InvariantCulture) == 0)
+                               if (value == null || value == "") {
+                                       Cache.SetCacheability (HttpCacheability.NoCache);
+                                       user_cache_control = null;
+                               } else if (String.Compare (value, "public", true, CultureInfo.InvariantCulture) == 0) {
                                        Cache.SetCacheability (HttpCacheability.Public);
-                               else if (String.Compare (value, "private", true, CultureInfo.InvariantCulture) == 0)
+                                       user_cache_control = "public";
+                               } else if (String.Compare (value, "private", true, CultureInfo.InvariantCulture) == 0) {
                                        Cache.SetCacheability (HttpCacheability.Private);
-                               else if (String.Compare (value, "no-cache", true, CultureInfo.InvariantCulture) == 0)
+                                       user_cache_control = "private";
+                               } else if (String.Compare (value, "no-cache", true, CultureInfo.InvariantCulture) == 0) {
                                        Cache.SetCacheability (HttpCacheability.NoCache);
-                               else
+                                       user_cache_control = "no-cache";
+                               } else
                                        throw new ArgumentException ("CacheControl property only allows `public', " +
                                                                     "`private' or no-cache, for different uses, use " +
                                                                     "Response.AppendHeader");
-                               user_cache_control = null;
                        }
 
-                       get {
-                               switch (Cache.Cacheability) {
-                               case (HttpCacheability)0:
-                               case HttpCacheability.NoCache:
-                                       return "no-cache";
-                               case HttpCacheability.Private: 
-                               case HttpCacheability.Server:
-                               case HttpCacheability.ServerAndPrivate:
-                                       return "private";
-                               case HttpCacheability.Public:
-                                       return "public";
-                               default:
-                                       throw new Exception ("Unknown internal state: " + Cache.Cacheability);
-                               }
-                       }
+                       get { return (user_cache_control != null) ? user_cache_control : "private"; }
                }
 #endregion