Updated
[mono.git] / mcs / class / System.Runtime.Remoting / MonoHttp / HttpListenerResponse.cs
index 7ddb646266166972defd3c763c6c7ec70128e066..dc3bdbca5a741d36cb73848ed3e4bc0842b437b9 100644 (file)
@@ -394,10 +394,9 @@ using System; using System.Net; namespace MonoHttp {
                        return false;
                }
 
-               internal void SendHeaders (bool closing)
+               internal void SendHeaders (bool closing, MemoryStream ms)
                {
                        //TODO: When do we send KeepAlive?
-                       MemoryStream ms = new MemoryStream ();
                        Encoding encoding = content_encoding;
                        if (encoding == null)
                                encoding = Encoding.Default;
@@ -445,11 +444,13 @@ using System; using System.Net; namespace MonoHttp {
                                        status_code == 413 || status_code == 414 || status_code == 500 ||
                                        status_code == 503);
 
-                       if (conn_close == false)
+                       if (conn_close == false) {
                                conn_close = (context.Request.Headers ["connection"] == "close");
+                               conn_close |= (v <= HttpVersion.Version10);
+                       }
 
                        // They sent both KeepAlive: true and Connection: close!?
-                       if (!chunked || conn_close)
+                       if (!keep_alive || conn_close)
                                headers.SetInternal ("Connection", "close");
 
                        if (chunked)
@@ -482,12 +483,12 @@ using System; using System.Net; namespace MonoHttp {
                        string headers_str = headers.ToString ();
                        writer.Write (headers_str);
                        writer.Flush ();
-                       // Perf.: use TCP_CORK if we're writing more?
                        int preamble = encoding.GetPreamble ().Length;
                        if (output_stream == null)
                                output_stream = context.Connection.GetResponseStream ();
 
-                       output_stream.InternalWrite (ms.GetBuffer (), 0 + preamble, (int) ms.Length - preamble);
+                       /* Assumes that the ms was at position 0 */
+                       ms.Position = preamble;
                        HeadersSent = true;
                }