Call SetEndOfSendNotification
[mono.git] / mcs / class / System.Web / System.Web / HttpResponse.cs
index a1ae238839987f6368f54daccd7247767134af2b..9aa99d9244bba7f1fefdf3e5dd6a763be74ae5a0 100644 (file)
@@ -7,7 +7,7 @@
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //      Marek Habersack <mhabersack@novell.com>
 //
-// Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -88,7 +88,7 @@ namespace System.Web
                // the headers that we compute here.
                //
 
-               NameValueCollection headers;
+               HttpHeaderCollection headers;
                bool headers_sent;
                NameValueCollection cached_headers;
 
@@ -111,10 +111,12 @@ namespace System.Web
                internal HttpResponse ()
                {
                        output_stream = new HttpResponseStream (this);
+                       writer = new HttpWriter (this);
                }
 
                public HttpResponse (TextWriter writer) : this ()
                {
+
                        this.writer = writer;
                }
 
@@ -127,8 +129,9 @@ namespace System.Web
                        if (worker_request != null)
                                use_chunked = (worker_request.GetHttpVersion () == "HTTP/1.1");
 #endif
+                       writer = new HttpWriter (this);
                }
-               
+
                internal TextWriter SetTextWriter (TextWriter writer)
                {
                        TextWriter prev = this.writer;
@@ -148,7 +151,12 @@ namespace System.Web
                                return version_header;
                        }
                }
-               
+
+               internal HttpContext Context {
+                       get { return context; }
+                       set { context = value; }
+               }
+                       
                internal string[] FileDependencies {
                        get {
                                if (fileDependencies == null || fileDependencies.Count == 0)
@@ -316,7 +324,7 @@ namespace System.Web
                public NameValueCollection Headers {
                        get {
                                if (headers == null)
-                                       headers = new NameValueCollection ();
+                                       headers = new HttpHeaderCollection ();
 
                                return headers;
                        }
@@ -338,11 +346,11 @@ namespace System.Web
 
                public TextWriter Output {
                        get {
-                               if (writer == null)
-                                       writer = new HttpWriter (this);
-
                                return writer;
                        }
+#if NET_4_0
+                       set { writer = value; }
+#endif
                }
 
                public Stream OutputStream {
@@ -494,8 +502,7 @@ namespace System.Web
                public void AppendHeader (string name, string value)
                {
                        if (headers_sent)
-                               throw new HttpException ("headers have been already sent");
-                       
+                               throw new HttpException ("Headers have been already sent");
 #if !TARGET_J2EE
                        if (String.Compare (name, "content-length", true, Helpers.InvariantCulture) == 0){
                                content_length = (long) UInt64.Parse (value);
@@ -534,7 +541,7 @@ namespace System.Web
                
                public string ApplyAppPathModifier (string virtualPath)
                {
-                       if (virtualPath == null)
+                       if (virtualPath == null || context == null)
                                return null;
                
                        if (virtualPath.Length == 0)
@@ -1019,25 +1026,49 @@ namespace System.Web
 
                public void Write (char ch)
                {
-                       Output.Write (ch);
+                       TextWriter writer = Output;
+#if NET_4_0
+                       // Emulating .NET
+                       if (writer == null)
+                               throw new NullReferenceException (".NET 4.0 emulation. A null value was found where an object was required.");
+#endif
+                       writer.Write (ch);
                }
 
                public void Write (object obj)
                {
+                       TextWriter writer = Output;
+#if NET_4_0
+                       // Emulating .NET
+                       if (writer == null)
+                               throw new NullReferenceException (".NET 4.0 emulation. A null value was found where an object was required.");
+#endif
                        if (obj == null)
                                return;
                        
-                       Output.Write (obj.ToString ());
+                       writer.Write (obj.ToString ());
                }
                
                public void Write (string s)
                {
-                       Output.Write (s);
+                       TextWriter writer = Output;
+#if NET_4_0
+                       // Emulating .NET
+                       if (writer == null)
+                               throw new NullReferenceException (".NET 4.0 emulation. A null value was found where an object was required.");
+#endif
+                       writer.Write (s);
                }
                
                public void Write (char [] buffer, int index, int count)
                {
-                       Output.Write (buffer, index, count);
+                       TextWriter writer = Output;
+#if NET_4_0
+                       // Emulating .NET
+                       if (writer == null)
+                               throw new NullReferenceException (".NET 4.0 emulation. A null value was found where an object was required.");
+#endif
+                       writer.Write (buffer, index, count);
                }
 
                internal void WriteFile (FileStream fs, long offset, long size)