diff options
Diffstat (limited to 'Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs | 97 |
1 files changed, 28 insertions, 69 deletions
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index fe545ecff..ef95b47c3 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -279,40 +279,10 @@ namespace Emby.Server.Implementations.HttpClientManager public async Task<Stream> Get(HttpRequestOptions options) { var response = await GetResponse(options).ConfigureAwait(false); - return response.Content; } /// <summary> - /// Performs a GET request and returns the resulting stream - /// </summary> - /// <param name="url">The URL.</param> - /// <param name="resourcePool">The resource pool.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task{Stream}.</returns> - public Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken) - { - return Get(new HttpRequestOptions - { - Url = url, - ResourcePool = resourcePool, - CancellationToken = cancellationToken, - BufferContent = resourcePool != null - }); - } - - /// <summary> - /// Gets the specified URL. - /// </summary> - /// <param name="url">The URL.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task{Stream}.</returns> - public Task<Stream> Get(string url, CancellationToken cancellationToken) - { - return Get(url, null, cancellationToken); - } - - /// <summary> /// send as an asynchronous operation. /// </summary> /// <param name="options">The options.</param> @@ -350,8 +320,6 @@ namespace Emby.Server.Implementations.HttpClientManager private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url) { - _logger.Info("Checking for cache file {0}", responseCachePath); - try { if (_fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow) @@ -429,10 +397,19 @@ namespace Emby.Server.Implementations.HttpClientManager { try { - var bytes = options.RequestContentBytes ?? - Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty); + // TODO: We can always put this in the options object if needed + var requestEncoding = Encoding.UTF8; + + var bytes = options.RequestContentBytes ?? requestEncoding.GetBytes(options.RequestContent ?? string.Empty); - httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded"; + var contentType = options.RequestContentType ?? "application/x-www-form-urlencoded"; + + if (options.AppendCharsetToMimeType) + { + contentType = contentType.TrimEnd(';') + "; charset=\"utf-8\""; + } + + httpWebRequest.ContentType = contentType; httpWebRequest.ContentLength = bytes.Length; (await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false)).Write(bytes, 0, bytes.Length); @@ -460,7 +437,14 @@ namespace Emby.Server.Implementations.HttpClientManager if (options.LogRequest) { - _logger.Info("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url); + if (options.LogRequestAsDebug) + { + _logger.Debug("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url); + } + else + { + _logger.Info("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url); + } } try @@ -590,26 +574,6 @@ namespace Emby.Server.Implementations.HttpClientManager } /// <summary> - /// Performs a POST request - /// </summary> - /// <param name="url">The URL.</param> - /// <param name="postData">Params to add to the POST data.</param> - /// <param name="resourcePool">The resource pool.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>stream on success, null on failure</returns> - public Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken) - { - return Post(new HttpRequestOptions - { - Url = url, - ResourcePool = resourcePool, - CancellationToken = cancellationToken, - BufferContent = resourcePool != null - - }, postData); - } - - /// <summary> /// Downloads the contents of a given url into a temporary location /// </summary> /// <param name="options">The options.</param> @@ -647,7 +611,14 @@ namespace Emby.Server.Implementations.HttpClientManager if (options.LogRequest) { - _logger.Info("HttpClientManager.GetTempFileResponse url: {0}", options.Url); + if (options.LogRequestAsDebug) + { + _logger.Debug("HttpClientManager.GetTempFileResponse url: {0}", options.Url); + } + else + { + _logger.Info("HttpClientManager.GetTempFileResponse url: {0}", options.Url); + } } var client = GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression); @@ -891,18 +862,6 @@ namespace Emby.Server.Implementations.HttpClientManager } } - /// <summary> - /// Posts the specified URL. - /// </summary> - /// <param name="url">The URL.</param> - /// <param name="postData">The post data.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task{Stream}.</returns> - public Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken) - { - return Post(url, postData, null, cancellationToken); - } - private Task<WebResponse> GetResponseAsync(WebRequest request, TimeSpan timeout) { var taskCompletion = new TaskCompletionSource<WebResponse>(); |
