Merge branch 'master' of \\\pk2010\Pithos\
[pithos-ms-client] / trunk / Pithos.Network / RestClient.cs
index 42aee54..d196752 100644 (file)
@@ -1,6 +1,6 @@
 // -----------------------------------------------------------------------
 // <copyright file="RestClient.cs" company="GRNet">
-// Copyright 2011 GRNET S.A. All rights reserved.
+// Copyright 2011-2012 GRNET S.A. All rights reserved.
 // 
 // Redistribution and use in source and binary forms, with or
 // without modification, are permitted provided that the following
@@ -121,7 +121,7 @@ namespace Pithos.Network
             TimedOut = false;
             var webRequest = base.GetWebRequest(address);            
             var request = (HttpWebRequest)webRequest;
-            request.ServicePoint.ConnectionLimit = 10;
+            request.ServicePoint.ConnectionLimit = 50;
             if (IfModifiedSince.HasValue)
                 request.IfModifiedSince = IfModifiedSince.Value;
             request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
@@ -226,7 +226,7 @@ namespace Pithos.Network
             //The response stream must be copied to avoid affecting other code by disposing of the 
             //original response stream.
             var stream = webResponse.GetResponseStream();            
-            using(var memStream=new MemoryStream((int) stream.Length))
+            using(var memStream=new MemoryStream())
             using (var reader = new StreamReader(memStream))
             {
                 stream.CopyTo(memStream);                
@@ -261,8 +261,19 @@ namespace Pithos.Network
 
             }, actualRetries);
 
-            var result = task.Result;
-            return result;
+            try
+            {
+                var result = task.Result;
+                return result;
+
+            }
+            catch (AggregateException exc)
+            {
+                //If the task fails, propagate the original exception
+                if (exc.InnerException!=null)
+                    throw exc.InnerException;
+                throw;
+            }
         }
 
         public void Head(string address,int retries=0)