New test.
[mono.git] / mcs / class / System / System.Net / HttpConnection.cs
index 20f6a1f34b3261027afd729fd00998cb5707a943..56579dc49f255a7fb590d678c98be13a173df5a4 100644 (file)
@@ -25,7 +25,9 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-#if NET_2_0
+
+#if NET_2_0 && SECURITY_DEP
+
 using System.IO;
 using System.Net.Sockets;
 using System.Reflection;
@@ -52,7 +54,6 @@ namespace System.Net {
                int chunked_uses;
                bool context_bound;
                bool secure;
-               X509Certificate2 cert;
                AsymmetricAlgorithm key;
 
                public HttpConnection (Socket sock, EndPointListener epl, bool secure, X509Certificate2 cert, AsymmetricAlgorithm key)
@@ -60,14 +61,17 @@ namespace System.Net {
                        this.sock = sock;
                        this.epl = epl;
                        this.secure = secure;
-                       this.cert = cert;
                        this.key = key;
                        if (secure == false) {
                                stream = new NetworkStream (sock, false);
                        } else {
+#if EMBEDDED_IN_1_0
+                               throw new NotImplementedException ();
+#else
                                SslServerStream ssl_stream = new SslServerStream (new NetworkStream (sock, false), cert, false, false);
                                ssl_stream.PrivateKeyCertSelectionDelegate += OnPVKSelection;
                                stream = ssl_stream;
+#endif
                        }
                        Init ();
                }
@@ -117,7 +121,11 @@ namespace System.Net {
                {
                        if (buffer == null)
                                buffer = new byte [BufferSize];
-                       stream.BeginRead (buffer, 0, BufferSize, OnRead, this);
+                       try {
+                               stream.BeginRead (buffer, 0, BufferSize, OnRead, this);
+                       } catch {
+                               sock.Close (); // stream disposed
+                       }
                }
 
                public RequestStream GetRequestStream (bool chunked, long contentlength)
@@ -157,7 +165,7 @@ namespace System.Net {
                                nread = stream.EndRead (ares);
                                ms.Write (buffer, 0, nread);
                        } catch (Exception e) {
-                               Console.WriteLine (e);
+                               //Console.WriteLine (e);
                                if (ms.Length > 0)
                                        SendError ();
                                sock.Close ();
@@ -296,8 +304,8 @@ namespace System.Net {
 
                public void Close ()
                {
-                       if (o_stream != null) {
-                               Stream st = o_stream;
+                       if (sock != null) {
+                               Stream st = GetResponseStream ();
                                st.Close ();
                                o_stream = null;
                        }
@@ -311,10 +319,21 @@ namespace System.Net {
                                        return;
                                }
 
-                               Socket s = sock;
-                               sock = null;
-                               s.Shutdown (SocketShutdown.Both);
-                               s.Close ();
+                               if (context.Response.Headers ["connection"] == "close") {
+                                       Socket s = sock;
+                                       sock = null;
+                                       try {
+                                               s.Shutdown (SocketShutdown.Both);
+                                       } catch {
+                                       } finally {
+                                               s.Close ();
+                                       }
+                               } else {
+                                       Init ();
+                                       BeginReadRequest ();
+                                       return;
+                               }
+
                                if (context_bound)
                                        epl.UnbindContext (context);
                        }