Remove duplicate code
This commit is contained in:
parent
3603c64fa6
commit
b117b364f2
|
@ -310,8 +310,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
|| !string.IsNullOrEmpty(options.RequestContent)
|
|| !string.IsNullOrEmpty(options.RequestContent)
|
||||||
|| httpMethod == HttpMethod.Post)
|
|| httpMethod == HttpMethod.Post)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
if (options.RequestContentBytes != null)
|
if (options.RequestContentBytes != null)
|
||||||
{
|
{
|
||||||
httpWebRequest.Content = new ByteArrayContent(options.RequestContentBytes);
|
httpWebRequest.Content = new ByteArrayContent(options.RequestContentBytes);
|
||||||
|
@ -333,15 +332,6 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
}
|
}
|
||||||
|
|
||||||
httpWebRequest.Headers.Add(HeaderNames.ContentType, contentType);*/
|
httpWebRequest.Headers.Add(HeaderNames.ContentType, contentType);*/
|
||||||
using (var response = await client.SendAsync(httpWebRequest).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
return await HandleResponseAsync(response, options).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new HttpException(ex.Message) { IsTimedOut = true };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.LogRequest)
|
if (options.LogRequest)
|
||||||
|
@ -349,8 +339,6 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
_logger.LogDebug("HttpClientManager {0}: {1}", httpMethod.ToString(), options.Url);
|
_logger.LogDebug("HttpClientManager {0}: {1}", httpMethod.ToString(), options.Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
options.CancellationToken.ThrowIfCancellationRequested();
|
options.CancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
/*if (!options.BufferContent)
|
/*if (!options.BufferContent)
|
||||||
|
@ -364,18 +352,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
return GetResponseInfo(response, await response.Content.ReadAsStreamAsync().ConfigureAwait(false), response.Content.Headers.ContentLength, response);
|
return GetResponseInfo(response, await response.Content.ReadAsStreamAsync().ConfigureAwait(false), response.Content.Headers.ContentLength, response);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
using (var response = await client.SendAsync(httpWebRequest).ConfigureAwait(false))
|
using (var response = await client.SendAsync(httpWebRequest, options.CancellationToken).ConfigureAwait(false))
|
||||||
{
|
|
||||||
return await HandleResponseAsync(response, options).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException ex)
|
|
||||||
{
|
|
||||||
throw GetCancellationException(options, options.CancellationToken, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<HttpResponseInfo> HandleResponseAsync(HttpResponseMessage response, HttpRequestOptions options)
|
|
||||||
{
|
{
|
||||||
await EnsureSuccessStatusCode(response, options).ConfigureAwait(false);
|
await EnsureSuccessStatusCode(response, options).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -384,7 +361,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
|
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
var memoryStream = new MemoryStream();
|
var memoryStream = new MemoryStream();
|
||||||
await stream.CopyToAsync(memoryStream, 81920, options.CancellationToken).ConfigureAwait(false);
|
await stream.CopyToAsync(memoryStream, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
|
||||||
memoryStream.Position = 0;
|
memoryStream.Position = 0;
|
||||||
|
|
||||||
var responseInfo = new HttpResponseInfo(response.Headers)
|
var responseInfo = new HttpResponseInfo(response.Headers)
|
||||||
|
@ -399,6 +376,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
return responseInfo;
|
return responseInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> Post(HttpRequestOptions options)
|
public Task<HttpResponseInfo> Post(HttpRequestOptions options)
|
||||||
=> SendAsync(options, HttpMethod.Post);
|
=> SendAsync(options, HttpMethod.Post);
|
||||||
|
@ -603,7 +581,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
var msg = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
_logger.LogError(msg);
|
_logger.LogError("HTTP request failed with message: {Message}", msg);
|
||||||
|
|
||||||
throw new HttpException(response.ReasonPhrase)
|
throw new HttpException(response.ReasonPhrase)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user