aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs')
-rw-r--r--MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs65
1 files changed, 35 insertions, 30 deletions
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index c29924c35..2e0035f5d 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -285,17 +285,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
EnsureSuccessStatusCode(httpResponse);
options.CancellationToken.ThrowIfCancellationRequested();
-
- return new HttpResponseInfo
- {
- Content = httpResponse.GetResponseStream(),
-
- StatusCode = httpResponse.StatusCode,
- ContentType = httpResponse.ContentType,
-
- Headers = httpResponse.Headers
- };
+ return GetResponseInfo(httpResponse, httpResponse.GetResponseStream(), GetContentLength(httpResponse));
}
using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
@@ -314,16 +305,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
memoryStream.Position = 0;
- return new HttpResponseInfo
- {
- Content = memoryStream,
-
- StatusCode = httpResponse.StatusCode,
-
- ContentType = httpResponse.ContentType,
-
- Headers = httpResponse.Headers
- };
+ return GetResponseInfo(httpResponse, memoryStream, memoryStream.Length);
}
}
}
@@ -367,6 +349,38 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
}
+ private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, Stream content, long? contentLength)
+ {
+ return new HttpResponseInfo
+ {
+ Content = content,
+
+ StatusCode = httpResponse.StatusCode,
+
+ ContentType = httpResponse.ContentType,
+
+ Headers = httpResponse.Headers,
+
+ ContentLength = contentLength
+ };
+ }
+
+ private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, string tempFile, long? contentLength)
+ {
+ return new HttpResponseInfo
+ {
+ TempFilePath = tempFile,
+
+ StatusCode = httpResponse.StatusCode,
+
+ ContentType = httpResponse.ContentType,
+
+ Headers = httpResponse.Headers,
+
+ ContentLength = contentLength
+ };
+ }
+
public Task<HttpResponseInfo> Post(HttpRequestOptions options)
{
return SendAsync(options, "POST");
@@ -493,16 +507,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
options.Progress.Report(100);
- return new HttpResponseInfo
- {
- TempFilePath = tempFile,
-
- StatusCode = httpResponse.StatusCode,
-
- ContentType = httpResponse.ContentType,
-
- Headers = httpResponse.Headers
- };
+ return GetResponseInfo(httpResponse, tempFile, contentLength);
}
}
catch (OperationCanceledException ex)