Revision 82db721b trunk/Pithos.Network/PithosClient.cs
b/trunk/Pithos.Network/PithosClient.cs | ||
---|---|---|
53 | 53 |
CopyHeaders(other); |
54 | 54 |
Timeout = other.Timeout; |
55 | 55 |
Retries = other.Retries; |
56 |
BaseAddress = other.BaseAddress; |
|
57 |
|
|
56 |
BaseAddress = other.BaseAddress; |
|
58 | 57 |
|
59 | 58 |
foreach (var parameter in other.Parameters) |
60 | 59 |
{ |
... | ... | |
96 | 95 |
} |
97 | 96 |
catch (WebException exc) |
98 | 97 |
{ |
99 |
if (exc.Response.ContentLength > 0) |
|
98 |
if (exc.Response!=null && exc.Response.ContentLength > 0)
|
|
100 | 99 |
{ |
101 |
string content; |
|
102 |
content = GetContent(exc.Response); |
|
100 |
string content = GetContent(exc.Response); |
|
103 | 101 |
Trace.TraceError(content); |
104 | 102 |
} |
105 | 103 |
throw; |
... | ... | |
124 | 122 |
|
125 | 123 |
var actualAddress = GetActualAddress(address); |
126 | 124 |
|
125 |
TraceStart("GET",actualAddress); |
|
126 |
|
|
127 | 127 |
var actualRetries = (retries == 0) ? Retries : retries; |
128 | 128 |
|
129 | 129 |
|
... | ... | |
172 | 172 |
if (address == null) |
173 | 173 |
throw new ArgumentNullException("address"); |
174 | 174 |
|
175 |
var actualAddress = GetActualAddress(address); |
|
176 |
|
|
175 |
var actualAddress = GetActualAddress(address); |
|
177 | 176 |
var actualRetries = (retries == 0) ? Retries : retries; |
177 |
|
|
178 | 178 |
var task = Retry(() => |
179 | 179 |
{ |
180 | 180 |
var uriString = String.Join("/",BaseAddress ,actualAddress); |
... | ... | |
184 | 184 |
if (ResponseHeaders!=null) |
185 | 185 |
ResponseHeaders.Clear(); |
186 | 186 |
|
187 |
TraceStart(method, uriString); |
|
188 |
|
|
187 | 189 |
var response = (HttpWebResponse)GetWebResponse(request); |
188 | 190 |
StatusCode = response.StatusCode; |
189 | 191 |
StatusDescription = response.StatusDescription; |
... | ... | |
195 | 197 |
task.Wait(); |
196 | 198 |
} |
197 | 199 |
|
200 |
private static void TraceStart(string method, string actualAddress) |
|
201 |
{ |
|
202 |
Trace.WriteLine(String.Format("[{0}] {1} {2}", method, DateTime.Now, actualAddress)); |
|
203 |
} |
|
204 |
|
|
198 | 205 |
private string GetActualAddress(string address) |
199 | 206 |
{ |
200 | 207 |
if (Parameters.Count == 0) |
... | ... | |
345 | 352 |
if (e is WebException) |
346 | 353 |
{ |
347 | 354 |
var we = (e as WebException); |
348 |
var statusCode = ((HttpWebResponse) we.Response).StatusCode; |
|
349 |
this.StatusCode = statusCode; |
|
355 |
|
|
356 |
var statusCode = HttpStatusCode.RequestTimeout; |
|
357 |
if (we.Response != null) |
|
358 |
{ |
|
359 |
statusCode = ((HttpWebResponse) we.Response).StatusCode; |
|
360 |
this.StatusCode = statusCode; |
|
361 |
} |
|
350 | 362 |
|
351 | 363 |
if (we.Status==WebExceptionStatus.Timeout || |
352 | 364 |
(we.Status==WebExceptionStatus.ProtocolError && statusCode==HttpStatusCode.ServiceUnavailable)) |
... | ... | |
364 | 376 |
} |
365 | 377 |
|
366 | 378 |
if (statusCode==HttpStatusCode.NotFound) |
367 |
return new Task<T>(() => default(T));
|
|
379 |
return Task<T>.Factory.StartNew(() => default(T));
|
|
368 | 380 |
} |
369 | 381 |
throw e; |
370 | 382 |
} |
Also available in: Unified diff