+++ /dev/null
-using System;\r
-using System.Security.Cryptography.X509Certificates;\r
-using System.IO;\r
-\r
-namespace System.Net\r
-{\r
- [Serializable]\r
- internal abstract class HttpProvider\r
- {\r
- #region Fields\r
-\r
- protected static int _defaultMaxResponseHeadersLength;\r
- protected static int _defaultMaxRedirectsNum = 50;\r
- \r
- protected Uri _originalUri;\r
- protected WebHeaderCollection _headers;\r
- protected bool _allowAutoRedirect;\r
- protected bool _allowWriteStreamBuffering = true;\r
- protected X509CertificateCollection _certificates;\r
- protected string _connectionGroupName;\r
- protected HttpContinueDelegate _continueDelegate;\r
- protected CookieContainer _cookieContainer;\r
- protected ICredentials _credentials;\r
- protected bool _keepAlive = true;\r
- protected int _maxResponseHeadersLength = _defaultMaxResponseHeadersLength;\r
- protected int _maxAutoRedirections = _defaultMaxRedirectsNum;\r
- protected int _readWriteTimeout = 300000;\r
- protected string _mediaType = string.Empty;\r
- protected string _methodName = "GET";\r
- protected bool _pipelined = true;\r
- protected bool _preAuthenticate;\r
- protected Version _version = HttpVersion.Version11;\r
- protected IWebProxy _proxy;\r
- protected bool _sendChunked;\r
- protected ServicePoint _servicePoint;\r
- protected int _timeout = 100000;\r
-\r
- protected bool _isAborted;\r
- protected long _contentLength = -1L;\r
-\r
- \r
- \r
-\r
- #endregion /* Fields */\r
-\r
- #region Constructors and Factory Methods\r
- protected HttpProvider(Uri uri)\r
- {\r
- _originalUri = uri;\r
- _headers = new WebHeaderCollection(true);\r
- _allowAutoRedirect = true;\r
- }\r
-\r
- public static HttpProvider GetHttpProvider(Uri uri)\r
- {\r
- return new VMWHttpProvider(uri);\r
- }\r
-\r
- public static HttpProvider GetHttpProvider(string provider, Uri uri)\r
- {\r
- Type type = Type.GetType(provider, true);\r
- if(type != null)\r
- return GetHttpProvider(type, uri);\r
- //log it as an error\r
- return new VMWHttpProvider(uri);\r
- }\r
-\r
- public static HttpProvider GetHttpProvider(Type provider, Uri uri)\r
- {\r
- try\r
- {\r
- return (HttpProvider)Activator.CreateInstance(provider, \r
- new object[]{uri}); \r
- }\r
- catch\r
- {\r
- //log it as an error\r
- return new VMWHttpProvider(uri);\r
- }\r
- }\r
-\r
- #endregion\r
-\r
- #region Properties\r
- internal virtual WebHeaderCollection Headers\r
- {\r
- get{return _headers;}\r
- set\r
- {\r
- if(IsRequestStarted ())\r
- throw new InvalidOperationException("Connection already opened");\r
- WebHeaderCollection newHeaders = new WebHeaderCollection (true);\r
- int count = value.Count;\r
- for (int i = 0; i < count; i++) \r
- newHeaders.Add (value.GetKey (i), value.Get (i));\r
-\r
- _headers = newHeaders;\r
- }\r
- }\r
-\r
- internal virtual bool AllowAutoRedirect\r
- {\r
- get{return _allowAutoRedirect;}\r
- set{_allowAutoRedirect = value;}\r
- }\r
-\r
- internal virtual bool AllowWriteStreamBuffering\r
- {\r
- get{return _allowWriteStreamBuffering;}\r
- set{_allowWriteStreamBuffering = value;}\r
- }\r
-\r
- internal virtual string ConnectionGroupName\r
- {\r
- get{return _connectionGroupName;}\r
- set{_connectionGroupName = value;}\r
- }\r
-\r
- internal virtual HttpContinueDelegate ContinueDelegate\r
- {\r
- get{return _continueDelegate;}\r
- set{_continueDelegate = value;}\r
- }\r
-\r
- internal virtual CookieContainer CookieContainer\r
- {\r
- get{return _cookieContainer;}\r
- set{_cookieContainer = value;}\r
- }\r
-\r
- internal virtual ICredentials Credentials\r
- {\r
- get{return _credentials;}\r
- set{_credentials = value;}\r
- }\r
- internal static int DefaultMaxResponseHeadersLength\r
- {\r
- get{return _defaultMaxResponseHeadersLength;}\r
- set\r
- {\r
- if (value < 0 && value != -1)\r
- throw new ArgumentOutOfRangeException("Argument should be positive");\r
- _defaultMaxResponseHeadersLength = value;\r
- }\r
- }\r
-\r
- internal virtual bool KeepAlive\r
- {\r
- get{return _keepAlive;}\r
- set{_keepAlive = value;}\r
- }\r
-\r
- internal virtual int MaxAutoRedirections\r
- {\r
- get{return _maxAutoRedirections;}\r
- set\r
- {\r
- if (value <= 0)\r
- throw new ArgumentException("Must be > 0", "value");\r
- _maxAutoRedirections = value;\r
- }\r
- }\r
-\r
- internal virtual int MaximumResponseHeadersLength\r
- {\r
- get{return _maxResponseHeadersLength;}\r
- set\r
- {\r
- if (IsRequestStarted())\r
- {\r
- throw new InvalidOperationException("Request has been already submitted.");\r
- }\r
- if (value < 0 && value != -1)\r
- throw new ArgumentOutOfRangeException("The argument must be positive or -1");\r
- _maxResponseHeadersLength = value;\r
- }\r
- }\r
- \r
- internal virtual string MediaType\r
- {\r
- get{return _mediaType;}\r
- set{_mediaType = value;}\r
- }\r
-\r
- internal virtual string MethodName\r
- {\r
- get{return _methodName;}\r
- set\r
- {\r
- if (value == null || value.Trim () == "")\r
- throw new ArgumentException ("not a valid method");\r
-\r
- _methodName = value;\r
- }\r
- }\r
- internal virtual bool Pipelined\r
- {\r
- get{return _pipelined;}\r
- set{_pipelined = value;}\r
- }\r
-\r
- internal virtual bool PreAuthenticate \r
- { \r
- get { return _preAuthenticate; }\r
- set { _preAuthenticate = value; }\r
- }\r
-\r
- internal virtual Version ProtocolVersion\r
- {\r
- get{return _version;}\r
- set\r
- {\r
- if (value != HttpVersion.Version10 && value != HttpVersion.Version11)\r
- throw new ArgumentException ("value");\r
-\r
- _version = value; \r
- }\r
- }\r
- internal virtual IWebProxy Proxy\r
- {\r
- get{return _proxy;}\r
- set\r
- {\r
- if(IsRequestStarted())\r
- throw new InvalidOperationException("Request already has been submitted");\r
- if(value == null)\r
- throw new ArgumentNullException("value");\r
- if(!(value is WebProxy))\r
- throw new NotImplementedException("The supported proxy objects only of type System.Net.WebProxy");\r
- _proxy = value;\r
- }\r
- }\r
- internal virtual int ReadWriteTimeout\r
- {\r
- get{return _readWriteTimeout;}\r
- set\r
- {\r
- if (IsRequestStarted())\r
- throw new InvalidOperationException("Request has been submitted.");\r
-\r
- if (value < 0 && value != -1)\r
- throw new ArgumentOutOfRangeException("value");\r
-\r
- _readWriteTimeout = value;\r
- }\r
- }\r
-\r
- internal virtual bool SendChunked\r
- {\r
- get{return _sendChunked;}\r
- set\r
- {\r
- if(IsRequestStarted ())\r
- throw new InvalidOperationException("Request has been submitted.");\r
- _sendChunked = value;\r
- }\r
- }\r
-\r
- internal virtual ServicePoint ServicePoint\r
- {\r
- get{return _servicePoint;}\r
- }\r
-\r
- internal virtual int Timeout\r
- {\r
- get{return _timeout;}\r
- set\r
- {\r
- if (value < -1)\r
- throw new ArgumentOutOfRangeException ("value");\r
-\r
- _timeout = value;\r
- }\r
- }\r
-\r
- internal virtual long ContentLength\r
- {\r
- get{return _contentLength;}\r
- set\r
- {\r
- if(value < 0)\r
- throw new ArgumentOutOfRangeException("value", "The Content-Length property value must be positive");\r
- _contentLength = value;\r
- }\r
- }\r
-\r
-\r
-\r
- #endregion\r
-\r
- #region Methods\r
-\r
- public virtual Uri GetOriginalAddress()\r
- {\r
- return _originalUri;\r
- }\r
-\r
- public virtual X509CertificateCollection GetX509Certificates()\r
- {\r
- if(_certificates == null)\r
- _certificates = new X509CertificateCollection();\r
- return _certificates;\r
- }\r
-\r
- public abstract bool IsRequestStarted();\r
-\r
- public abstract Uri GetAddress();\r
-\r
- public abstract bool IsHaveResponse();\r
-\r
- public abstract void Abort();\r
-\r
- public abstract Stream GetRequestStream();\r
-\r
- public abstract WebResponse GetResponse();\r
-\r
- public abstract IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);\r
-\r
- public abstract Stream EndGetRequestStream(IAsyncResult asyncResult);\r
-\r
- public abstract IAsyncResult BeginGetResponse(AsyncCallback callback, object state);\r
-\r
- public abstract WebResponse EndGetResponse(IAsyncResult asyncResult);\r
-\r
-\r
- #endregion\r
-\r
-\r
- }\r
-}\r