dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System/Net HttpWebRequest.cs,1.10,1.


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Net HttpWebRequest.cs,1.10,1.11 WebRequest.cs,1.8,1.9
Date: Sat, 31 May 2003 03:53:37 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System/Net
In directory subversions:/tmp/cvs-serv31699/System/Net

Modified Files:
        HttpWebRequest.cs WebRequest.cs 
Log Message:
Add SSL support to HttpWebRequest (and HttpWebResponse is automatically fixed)


Index: HttpWebRequest.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/HttpWebRequest.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** HttpWebRequest.cs   19 Nov 2002 20:38:26 -0000      1.10
--- HttpWebRequest.cs   31 May 2003 07:53:35 -0000      1.11
***************
*** 34,37 ****
--- 34,38 ----
  using System.Threading;
  using System.Net.Sockets;
+ using DotGNU.SSL;
  
  public class HttpWebRequest : WebRequest
***************
*** 61,64 ****
--- 62,66 ----
        private int timeout;
        private string mediaType=null;
+       private bool isSecured=false;
  
  // other useful variables
***************
*** 73,76 ****
--- 75,79 ----
                this.address=uri;
                this.originalUri=uri;
+               this.isSecured=String.Equals(uri.Scheme,Uri.UriSchemeHttps);
                this.method="GET";
                this.headers.SetInternal ("Host", uri.Authority);
***************
*** 177,185 ****
                {
                        outStream=new HttpStream(this);
                        // which is the response stream as well 
                }
!               outStream.Flush();
!               this.response=new HttpWebResponse(this,this.outStream);
!               this.haveResponse=true; // I hope this is correct
                return this.response; 
        }
--- 180,191 ----
                {
                        outStream=new HttpStream(this);
+                       outStream.Flush();
                        // which is the response stream as well 
                }
!               if(this.response==null)
!               {
!                       this.response=new HttpWebResponse(this,this.outStream);
!                       this.haveResponse=true; // I hope this is correct
!               }
                return this.response; 
        }
***************
*** 610,622 ****
                return false;
        }
!       private class HttpStream : NetworkStream
        {       
                private HttpWebRequest request;
!               public HttpStream(HttpWebRequest req) :
!                       base(HttpStream.OpenSocket(req),true)
                {
                        this.request=req;
                        SendHeaders();
                }
                private static Socket OpenSocket(HttpWebRequest req)
                {
--- 616,718 ----
                return false;
        }
! 
!       private class HttpStream : Stream
        {       
                private HttpWebRequest request;
!               private Stream underlying=null;
!               private static SecureConnection secured=null;
! 
!               public HttpStream(HttpWebRequest req) 
!                       : this(req, HttpStream.OpenStream(req))
!               {
!               }
! 
!               public HttpStream(HttpWebRequest req, Stream underlying)
                {
                        this.request=req;
+                       this.underlying=underlying;
                        SendHeaders();
                }
+ 
+               // Stub out all stream functionality.
+               public override void Flush() 
+               {
+                       underlying.Flush();
+               }
+               
+               public override int Read(byte[] buffer, int offset, int count)
+               {
+                       return underlying.Read(buffer, offset, count);
+               }
+               
+               public override int ReadByte() 
+               {
+                       return underlying.ReadByte();
+               }
+ 
+               public override long Seek(long offset, SeekOrigin origin)
+               {
+                       return underlying.Seek(offset, origin);
+               }
+               
+               public override void SetLength(long value)
+               {
+                       underlying.SetLength(value);
+               }
+ 
+               public override void Write(byte[] buffer, int offset, int count)
+               {
+                       underlying.Write(buffer, offset, count);
+               }
+ 
+               public override void WriteByte(byte value) 
+               {
+                       underlying.WriteByte(value);
+               }
+ 
+               public override bool CanRead 
+               {
+                       get 
+                       {
+                               return underlying.CanRead;
+                       } 
+               }
+ 
+               public override bool CanSeek 
+               {
+                       get 
+                       {
+                               return underlying.CanSeek; 
+                       } 
+               }
+ 
+               public override bool CanWrite 
+               {
+                       get 
+                       {
+                               return underlying.CanWrite;
+                       }
+               }
+               
+               public override long Length
+               {
+                       get
+                       {
+                               return underlying.Length;
+                       }
+               }
+ 
+               public override long Position
+               {
+                       get
+                       {
+                               return underlying.Position;
+                       }
+                       set
+                       {
+                               underlying.Position = value;
+                       }
+               }
+ 
                private static Socket OpenSocket(HttpWebRequest req)
                {
***************
*** 629,632 ****
--- 725,746 ----
                        return server;
                }
+ 
+               private static Stream OpenStream(HttpWebRequest req)
+               {
+                       Socket sock=OpenSocket(req);
+                       if(req.isSecured)
+                       {
+                               if(secured==null)
+                               {
+                                       secured=new SecureConnection();
+                               }
+                               return secured.OpenStream(sock);
+                       }
+                       else
+                       {
+                               return new NetworkStream(sock,true);
+                       }
+               }
+ 
                private void SendHeaders()
                {
***************
*** 644,647 ****
--- 758,791 ----
                }
        } //internal class
+ 
+       private class SecureConnection: IDisposable
+       {
+               ISecureSessionProvider provider=null;
+               ISecureSession session=null;
+ 
+               public SecureConnection()
+               {
+                       provider = SessionProviderFactory.GetProvider();
+                       session = 
provider.CreateClientSession(Protocol.AutoDetect);
+               }
+               
+               public Stream OpenStream(Socket sock)
+               {
+                       return session.PerformHandshake(sock);
+               }
+ 
+               public void Dispose()
+               {
+                       if(session!=null)
+                       {
+                               session.Dispose();
+                               session=null;
+                       }
+               }
+               ~SecureConnection()
+               {
+                       Dispose();
+               }
+       }
  }//class
  

Index: WebRequest.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/WebRequest.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** WebRequest.cs       9 May 2003 17:49:43 -0000       1.8
--- WebRequest.cs       31 May 2003 07:53:35 -0000      1.9
***************
*** 47,51 ****
  
                // Register the prefix types here
-               RegisterPrefix(Uri.UriSchemeFtp,   new WebRequestCreator());
                RegisterPrefix(Uri.UriSchemeHttp,  new WebRequestCreator());
                RegisterPrefix(Uri.UriSchemeHttps, new WebRequestCreator());
--- 47,50 ----
***************
*** 134,138 ****
                if(CheckUriValidity(requestUri, true))
                {
!                       if(requestUri.Scheme=="http")
                        {
                                return new HttpWebRequest(requestUri);
--- 133,138 ----
                if(CheckUriValidity(requestUri, true))
                {
!                       if(String.Equals(requestUri.Scheme, Uri.UriSchemeHttp) 
||
!                               String.Equals(requestUri.Scheme, 
Uri.UriSchemeHttps))
                        {
                                return new HttpWebRequest(requestUri);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]