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 WebRequest.cs,1.5,1.6


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Net WebRequest.cs,1.5,1.6
Date: Thu, 19 Dec 2002 22:13:06 -0500

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

Modified Files:
        WebRequest.cs 
Log Message:
Jason Lee's patches to System.Net.WebRequest + a bit of cleaning up by me


Index: WebRequest.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/WebRequest.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** WebRequest.cs       18 Nov 2002 18:58:04 -0000      1.5
--- WebRequest.cs       20 Dec 2002 03:13:04 -0000      1.6
***************
*** 4,7 ****
--- 4,9 ----
   * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
   *
+  * With contributions from Jason Lee <address@hidden>
+  * 
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
***************
*** 26,42 ****
  using System.Collections;
  
! public class WebRequest : MarshalByRefObject
  {
!       private String              connectionGroupName;
!       private Int64               contentLength;
!       private String              contentType;
!       private ICredentials        credentials;
        private WebHeaderCollection headers;
!       private String              method;
!       private Boolean             preAuthenticate;
!       private IWebProxy           proxy;
!       private Uri                 requestUri;
!       private Int32               timeout;
!       private static Hashtable    prefixes=new Hashtable();
  
        protected WebRequest()
--- 28,44 ----
  using System.Collections;
  
! public abstract class WebRequest : MarshalByRefObject
  {
!       private String                          connectionGroupName;
!       private Int64                           contentLength;
!       private String                          contentType;
!       private ICredentials            credentials;
        private WebHeaderCollection headers;
!       private String                          method;
!       private Boolean                         preAuthenticate;
!       private IWebProxy                       proxy;
!       private Uri                                     requestUri;
!       private Int32                           timeout;
!       private static Hashtable        prefixes=new Hashtable();
  
        protected WebRequest()
***************
*** 52,58 ****
                timeout = 0;
                prefixes.Clear();
-       }
  
!       // TODO: need proper translatable strings for the exceptions below.
  
        public virtual void Abort()
--- 54,66 ----
                timeout = 0;
                prefixes.Clear();
  
!               // Register the prefix types here
!               RegisterPrefix(Uri.UriSchemeFtp,   new WebRequestCreator());
!               RegisterPrefix(Uri.UriSchemeHttp,  new WebRequestCreator());
!               RegisterPrefix(Uri.UriSchemeHttps, new WebRequestCreator());
! 
!               // TODO: More prefixes, such as those contained in Uri should 
come later
!               
!       }
  
        public virtual void Abort()
***************
*** 71,123 ****
        }
  
!       [ TODO ]
!       public static WebRequest Create(string requestUriString)
        {
                if (requestUriString == null)
                {
!                       throw new ArgumentNullException("requestUriString", 
S._("Arg_NotNull"));
                }
  
                Uri requestUri = new Uri(requestUriString);             
! 
                return Create(requestUri);
        }
  
!       [ TODO ]
        public static WebRequest Create(Uri requestUri)
        {
-               // TODO: Match Uri against complete Uri and scheme and find out
-               // if it is supported, otherwise throw up an error
-               // throw new NotSupportedException("Create");
  
!               // TODO: the URI format is invalid
!               // throw new UriFormatException("requestUriString");
  
                // TODO: this client does not have the permission to connect to 
the URI or
                // the URI that the request is redirected to.
                // throw new SecurityException("requestUriString");
! 
                return null;
        }
  
!       [ TODO ]
        public static WebRequest CreateDefault(Uri requestUri)
        {
-               // TODO: Find out if just scheme is supported, otherwise throw 
up an error
-               // do not check for the complete Uri (in the case of longer 
Uri's passed).
-               // see spec
-               // throw new NotSupportedException("CreateDefault");
- 
-               // TODO: the URI format is invalid
-               // throw new UriFormatException("requestUriString");
- 
                // TODO: this client does not have the permission to connect to 
the URI or
                // the URI that the request is redirected to.
                // throw new SecurityException("requestUriString");
!               if(requestUri.Scheme=="http")
                {
!                       return new HttpWebRequest(requestUri);
                }
!               throw new NotSupportedException("CreateDefault");
        }
  
--- 79,144 ----
        }
  
!       public static WebRequest Create(String requestUriString)
        {
                if (requestUriString == null)
                {
!                       throw new ArgumentNullException("requestUriString",
!                                                                               
        S._("Arg_NotNull"));
                }
  
                Uri requestUri = new Uri(requestUriString);             
!               
                return Create(requestUri);
+               
        }
  
!       // This method will attempt to create a particular subclass of 
WebRequest
!       // based on the scheme from the uri passed in. Currently on 
HttpWebRequest
!       // is supported.
        public static WebRequest Create(Uri requestUri)
        {
  
!               IWebRequestCreate theCreator = null;
!               
!               if(CheckUriValidity(requestUri, false))
!               {
! 
!                       // Check here to see if the Uri scheme exists in the
!                       // prefixes table and if so, then return back the
!                       // proper WebRequest for it
!                       theCreator = (prefixes[requestUri.Scheme] as 
IWebRequestCreate);
!                       
!                       if(theCreator!=null)
!                       {
!                               return theCreator.Create(requestUri);
!                       }
  
                // TODO: this client does not have the permission to connect to 
the URI or
                // the URI that the request is redirected to.
                // throw new SecurityException("requestUriString");
!               }
!                  
                return null;
        }
  
!       // This method will attempt to create a 'default' WebRequest. In this 
case
!       // we're assuming the default is a HttpWebRequest. Non-default requests
!       // will need to be created with the Create method.
        public static WebRequest CreateDefault(Uri requestUri)
        {
                // TODO: this client does not have the permission to connect to 
the URI or
                // the URI that the request is redirected to.
                // throw new SecurityException("requestUriString");
!               if(CheckUriValidity(requestUri, true))
                {
!                       if(requestUri.Scheme=="http")
!                       {
!                               return new HttpWebRequest(requestUri);
!                       }
!                       throw new NotSupportedException("CreateDefault");
                }
! 
!               return null;
!               
        }
  
***************
*** 142,147 ****
        }
  
!       [ TODO ]
!       public static bool RegisterPrefix(string prefix, IWebRequestCreate 
creator)
        {
                if (prefix== null)
--- 163,167 ----
        }
  
!       public static bool RegisterPrefix(String prefix, IWebRequestCreate 
creator)
        {
                if (prefix== null)
***************
*** 155,162 ****
                }
  
!               // TODO: further implementation...
  
!               return false;
        }
  
        public virtual string ConnectionGroupName 
--- 175,241 ----
                }
  
!               if(prefixes.Contains( prefix.ToLower() ))
!               {
!                       return false;
!               }
!               else
!               {
!                       prefixes.Add(prefix.ToLower(), creator);
!               }
!                       
!               return true;
!       }
  
!       private static bool CheckUriValidity(Uri requestUri, bool defaultUri)
!       {
! 
!               // defaultUri is provided so we can throw the proper exception
!               // based on whether or not we're referred from the regular 
Create 
!               // method or if we're actually using the DefaultCreate
!               
!               if (requestUri == null)
!               {
!                       throw new ArgumentNullException ("requestUri");
!               }
! 
!               if(!Uri.CheckSchemeName(requestUri.Scheme))
!               {
!                       if(defaultUri)
!                       {
!                               throw new 
NotSupportedException("CreateDefault");
!                       }
!                       else
!                       {
!                               throw new NotSupportedException("Create");
!                       }
!                       
!               }
! 
!               // TODO: There's probably additional checking for what 
constitutes the
!               // query portion of a Uri, but I'm not sure what it is yet. 
Probably
!               // look into this later.
!               if(requestUri.HostNameType.Equals(UriHostNameType.Unknown))
!               {
!                       throw new UriFormatException("requestUri");
!               }
! 
!               return true;
!       }
! 
!       // Internal classes needed to use with the RegisterPrefix method as per 
spec
!       // These could have been done as 'helpers' but they're only needed in 
this class
!       internal class WebRequestCreator : IWebRequestCreate
!       {
! 
!       internal WebRequestCreator()
!               {}
!       
!       public WebRequest Create(Uri uri)
!               {
!                       return new HttpWebRequest(uri);
!               }
        }
+ 
+       // properties
  
        public virtual string ConnectionGroupName 




reply via email to

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