mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-06 10:16:18 +00:00
tightened up image saving to reduce knowledge of file names
This commit is contained in:
@@ -104,6 +104,92 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||
return client;
|
||||
}
|
||||
|
||||
public async Task<HttpResponseInfo> GetResponse(HttpRequestOptions options)
|
||||
{
|
||||
ValidateParams(options.Url, options.CancellationToken);
|
||||
|
||||
options.CancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var client = GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression);
|
||||
|
||||
if ((DateTime.UtcNow - client.LastTimeout).TotalSeconds < 30)
|
||||
{
|
||||
throw new HttpException(string.Format("Cancelling connection to {0} due to a previous timeout.", options.Url)) { IsTimedOut = true };
|
||||
}
|
||||
|
||||
using (var message = GetHttpRequestMessage(options))
|
||||
{
|
||||
if (options.ResourcePool != null)
|
||||
{
|
||||
await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if ((DateTime.UtcNow - client.LastTimeout).TotalSeconds < 30)
|
||||
{
|
||||
if (options.ResourcePool != null)
|
||||
{
|
||||
options.ResourcePool.Release();
|
||||
}
|
||||
|
||||
throw new HttpException(string.Format("Connection to {0} timed out", options.Url)) { IsTimedOut = true };
|
||||
}
|
||||
|
||||
_logger.Info("HttpClientManager.Get url: {0}", options.Url);
|
||||
|
||||
try
|
||||
{
|
||||
options.CancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var response = await client.HttpClient.SendAsync(message, HttpCompletionOption.ResponseContentRead, options.CancellationToken).ConfigureAwait(false);
|
||||
|
||||
EnsureSuccessStatusCode(response);
|
||||
|
||||
options.CancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
return new HttpResponseInfo
|
||||
{
|
||||
Content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false),
|
||||
|
||||
StatusCode = response.StatusCode,
|
||||
|
||||
ContentType = response.Content.Headers.ContentType.MediaType
|
||||
};
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
var exception = GetCancellationException(options.Url, options.CancellationToken, ex);
|
||||
|
||||
var httpException = exception as HttpException;
|
||||
|
||||
if (httpException != null && httpException.IsTimedOut)
|
||||
{
|
||||
client.LastTimeout = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
throw exception;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting response from " + options.Url, ex);
|
||||
|
||||
throw new HttpException(ex.Message, ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting response from " + options.Url, ex);
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (options.ResourcePool != null)
|
||||
{
|
||||
options.ResourcePool.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a GET request and returns the resulting stream
|
||||
/// </summary>
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Class HttpResponseOutput
|
||||
/// </summary>
|
||||
public class HttpResponseInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the URL.
|
||||
/// </summary>
|
||||
/// <value>The URL.</value>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the etag.
|
||||
/// </summary>
|
||||
/// <value>The etag.</value>
|
||||
public string Etag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the last modified.
|
||||
/// </summary>
|
||||
/// <value>The last modified.</value>
|
||||
public DateTime? LastModified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the expires.
|
||||
/// </summary>
|
||||
/// <value>The expires.</value>
|
||||
public DateTime? Expires { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether [must revalidate].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [must revalidate]; otherwise, <c>false</c>.</value>
|
||||
public bool MustRevalidate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the request date.
|
||||
/// </summary>
|
||||
/// <value>The request date.</value>
|
||||
public DateTime RequestDate { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user