Reduced buffer size while hashing to 16K
[pithos-ms-client] / trunk / Pithos.Network / RestClient.cs
index 70b5740..8eb30c8 100644 (file)
@@ -96,7 +96,10 @@ namespace Pithos.Network
 
         public RestClient():base()
         {
-            
+            //The maximum error response must be large because missing server hashes are return as a Conflivt (409) error response
+            //Any value above 2^21-1 will result in an empty response.
+            //-1 essentially ignores the maximum length
+            HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
         }
 
        
@@ -104,9 +107,16 @@ namespace Pithos.Network
             : base()
         {
             if (other==null)
+                //Log.ErrorFormat("[ERROR] No parameters provided to the rest client. \n{0}\n", other);
                 throw new ArgumentNullException("other");
             Contract.EndContractBlock();
 
+            //The maximum error response must be large because missing server hashes are return as a Conflivt (409) error response
+            //Any value above 2^21-1 will result in an empty response.
+            //-1 essentially ignores the maximum length
+            HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
+            
+
             CopyHeaders(other);
             Timeout = other.Timeout;
             Retries = other.Retries;
@@ -126,6 +136,7 @@ namespace Pithos.Network
             TimedOut = false;
             var webRequest = base.GetWebRequest(address);            
             var request = (HttpWebRequest)webRequest;
+            request.CookieContainer=new CookieContainer();
             request.ServicePoint.ConnectionLimit = 50;
             if (IfModifiedSince.HasValue)
                 request.IfModifiedSince = IfModifiedSince.Value;
@@ -268,8 +279,8 @@ namespace Pithos.Network
             var uriString = String.Join("/", BaseAddress.TrimEnd('/'), actualAddress);
 
             var task = Retry(() =>
-            {                
-                var content = base.DownloadString(uriString);
+            {                                
+                var content = DownloadString(uriString);
 
                 if (StatusCode == HttpStatusCode.NoContent)
                     return String.Empty;
@@ -279,7 +290,7 @@ namespace Pithos.Network
 
             try
             {
-                var result = task.Result;
+                    var result = task.Result;
                 return result;
 
             }
@@ -298,9 +309,14 @@ namespace Pithos.Network
             RetryWithoutContent(address, retries, "HEAD");
         }
 
-        public void PutWithRetry(string address, int retries = 0)
+        public void PutWithRetry(string address, int retries = 0, string contentType=null)
         {
-            RetryWithoutContent(address, retries, "PUT");
+            RetryWithoutContent(address, retries, "PUT",contentType);
+        }
+
+        public void PostWithRetry(string address,string contentType)
+        {            
+            RetryWithoutContent(address, 0, "POST",contentType);
         }
 
         public void DeleteWithRetry(string address,int retries=0)
@@ -331,7 +347,7 @@ namespace Pithos.Network
             Headers.Add(headerName,value);
         }
 
-        private void RetryWithoutContent(string address, int retries, string method)
+        private void RetryWithoutContent(string address, int retries, string method,string contentType=null)
         {
             if (address == null)
                 throw new ArgumentNullException("address");
@@ -344,6 +360,11 @@ namespace Pithos.Network
                 var uriString = String.Join("/",BaseAddress ,actualAddress);
                 var uri = new Uri(uriString);
                 var request =  GetWebRequest(uri);
+                if (contentType!=null)
+                {
+                    request.ContentType = contentType;
+                    request.ContentLength = 0;
+                }
                 request.Method = method;
                 if (ResponseHeaders!=null)
                     ResponseHeaders.Clear();
@@ -564,6 +585,7 @@ namespace Pithos.Network
                         .ToDictionary(t => t.Name, t => t.Value);
             return dict;
         }
+
     }
 
     public class RetryException:Exception