diff options
| author | Bond_009 <bond.009@outlook.com> | 2019-06-14 17:14:42 +0200 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2019-07-06 20:04:45 +0200 |
| commit | 3603c64fa6033eca4a92c4f537fddc182817998a (patch) | |
| tree | f5b17389712469ffe32e6ea55c72fdee200d095f | |
| parent | d405a400aaa5f9676cc2ce9159b562f94233dcd5 (diff) | |
Use HttpResponseHeaders instead of a dictionary
| -rw-r--r-- | Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs | 67 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/HttpResponseInfo.cs | 11 |
2 files changed, 26 insertions, 52 deletions
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index 987657bcb..7af0efc17 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -4,8 +4,6 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Configuration; @@ -389,52 +387,16 @@ namespace Emby.Server.Implementations.HttpClientManager await stream.CopyToAsync(memoryStream, 81920, options.CancellationToken).ConfigureAwait(false); memoryStream.Position = 0; - return GetResponseInfo(response, memoryStream, memoryStream.Length); - } - } - - private HttpResponseInfo GetResponseInfo(HttpResponseMessage httpResponse, Stream content, long? contentLength) - { - var responseInfo = new HttpResponseInfo() - { - Content = content, - StatusCode = httpResponse.StatusCode, - ContentType = httpResponse.Content.Headers.ContentType?.MediaType, - ContentLength = contentLength, - ResponseUrl = httpResponse.Content.Headers.ContentLocation?.ToString() - }; - - if (httpResponse.Headers != null) - { - SetHeaders(httpResponse.Content.Headers, responseInfo); - } - - return responseInfo; - } - - private HttpResponseInfo GetResponseInfo(HttpResponseMessage httpResponse, string tempFile, long? contentLength) - { - var responseInfo = new HttpResponseInfo - { - TempFilePath = tempFile, - StatusCode = httpResponse.StatusCode, - ContentType = httpResponse.Content.Headers.ContentType?.MediaType, - ContentLength = contentLength - }; - - if (httpResponse.Headers != null) - { - SetHeaders(httpResponse.Content.Headers, responseInfo); - } - - return responseInfo; - } + var responseInfo = new HttpResponseInfo(response.Headers) + { + Content = memoryStream, + StatusCode = response.StatusCode, + ContentType = response.Content.Headers.ContentType?.MediaType, + ContentLength = memoryStream.Length, + ResponseUrl = response.Content.Headers.ContentLocation?.ToString() + }; - private static void SetHeaders(HttpContentHeaders headers, HttpResponseInfo responseInfo) - { - foreach (var header in headers) - { - responseInfo.Headers[header.Key] = string.Join(", ", header.Value); + return responseInfo; } } @@ -496,8 +458,15 @@ namespace Emby.Server.Implementations.HttpClientManager options.Progress.Report(100); - var contentLength = response.Content.Headers.ContentLength; - return GetResponseInfo(response, tempFile, contentLength); + var responseInfo = new HttpResponseInfo(response.Headers) + { + TempFilePath = tempFile, + StatusCode = response.StatusCode, + ContentType = response.Content.Headers.ContentType?.MediaType, + ContentLength = response.Content.Headers.ContentLength + }; + + return responseInfo; } } catch (Exception ex) diff --git a/MediaBrowser.Common/Net/HttpResponseInfo.cs b/MediaBrowser.Common/Net/HttpResponseInfo.cs index aa496adac..cd9feabfe 100644 --- a/MediaBrowser.Common/Net/HttpResponseInfo.cs +++ b/MediaBrowser.Common/Net/HttpResponseInfo.cs @@ -1,7 +1,7 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; +using System.Net.Http.Headers; namespace MediaBrowser.Common.Net { @@ -50,11 +50,16 @@ namespace MediaBrowser.Common.Net /// Gets or sets the headers. /// </summary> /// <value>The headers.</value> - public Dictionary<string, string> Headers { get; set; } + public HttpResponseHeaders Headers { get; set; } public HttpResponseInfo() { - Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); + + } + + public HttpResponseInfo(HttpResponseHeaders headers) + { + Headers = headers; } public void Dispose() |
