2009-06-04 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web / HttpResponse.cs
index 2c7ce483fa2abc4db45da84ad6a3cbfde401f766..7ed591b59ee7c4bd7f11d7f83c6a41ab26fa822c 100644 (file)
@@ -68,8 +68,8 @@ namespace System.Web {
                CachedRawResponse cached_response;
                string user_cache_control = "private";
                string redirect_location;
-               
-               static string version_header;
+               string version_header;
+               bool version_header_checked;
                
                //
                // Negative Content-Length means we auto-compute the size of content-length
@@ -105,17 +105,6 @@ namespace System.Web {
                Encoding headerEncoding;
 #endif
 
-               static HttpResponse ()
-               {
-#if NET_2_0
-                       HttpRuntimeSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/httpRuntime") as HttpRuntimeSection;
-#else
-                       HttpRuntimeConfig config = HttpContext.GetAppConfig ("system.web/httpRuntime") as HttpRuntimeConfig;
-#endif
-                       if (config != null && config.EnableVersionHeader)
-                               version_header = Environment.Version.ToString (3);
-               }
-               
                internal HttpResponse ()
                {
                        output_stream = new HttpResponseStream (this);
@@ -144,6 +133,23 @@ namespace System.Web {
                        return prev;
                }
 
+               internal string VersionHeader {
+                       get {
+                               if (!version_header_checked && version_header == null) {
+                                       version_header_checked = true;
+#if NET_2_0
+                                       HttpRuntimeSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/httpRuntime") as HttpRuntimeSection;
+#else
+                                       HttpRuntimeConfig config = HttpContext.GetAppConfig ("system.web/httpRuntime") as HttpRuntimeConfig;
+#endif
+                                       if (config != null && config.EnableVersionHeader)
+                                               version_header = Environment.Version.ToString (3);
+                               }
+
+                               return version_header;
+                       }
+               }
+               
                internal string[] FileDependencies {
                        get {
                                if (fileDependencies == null || fileDependencies.Count == 0)
@@ -608,7 +614,10 @@ namespace System.Web {
                        content_length = -1;
                        content_type = "text/html";
                        transfer_encoding = null;
-                       user_cache_control = null;
+                       user_cache_control = "private";
+                       if (cache_policy != null)
+                               cache_policy.Cacheability = HttpCacheability.Private;
+
                        if (headers != null)
                                headers.Clear ();
                }
@@ -672,8 +681,9 @@ namespace System.Web {
                                write_headers.Add ("Location", redirect_location);
                        
 #if !TARGET_J2EE
-                       if (version_header != null)
-                               write_headers.Add ("X-AspNet-Version", version_header);
+                       string vh = VersionHeader;
+                       if (vh != null)
+                               write_headers.Add ("X-AspNet-Version", vh);
 
                        //
                        // If Content-Length is set.
@@ -781,15 +791,21 @@ namespace System.Web {
                        if (WorkerRequest != null) {
                                string header_name;
                                string[] values;
+                               int header_index;
                                
                                for (int i = 0; i < write_headers.Count; i++) {
                                        header_name = write_headers.GetKey (i);
+                                       header_index = HttpWorkerRequest.GetKnownResponseHeaderIndex (header_name);
                                        values = write_headers.GetValues (i);
                                        if (values == null)
                                                continue;
                                        
-                                       foreach (string val in values)
-                                               WorkerRequest.SendUnknownResponseHeader (header_name, val);
+                                       foreach (string val in values) {
+                                               if (header_index > -1)
+                                                       WorkerRequest.SendKnownResponseHeader (header_index, val);
+                                               else
+                                                       WorkerRequest.SendUnknownResponseHeader (header_name, val);
+                                       }
                                }
                        }
                }