mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-18 16:29:41 +02:00
New: Use HTTP/2 in HttpClient
(cherry picked from commit 9ee09b9186a267844bd99b1a33f5959ba6461750)
This commit is contained in:
parent
531e948687
commit
d61ce6112b
@ -45,7 +45,11 @@ public ManagedHttpDispatcher(IHttpProxySettingsProvider proxySettingsProvider,
|
|||||||
|
|
||||||
public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
|
public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
|
||||||
{
|
{
|
||||||
var requestMessage = new HttpRequestMessage(request.Method, (Uri)request.Url);
|
var requestMessage = new HttpRequestMessage(request.Method, (Uri)request.Url)
|
||||||
|
{
|
||||||
|
Version = HttpVersion.Version20,
|
||||||
|
VersionPolicy = HttpVersionPolicy.RequestVersionOrLower
|
||||||
|
};
|
||||||
requestMessage.Headers.UserAgent.ParseAdd(_userAgentBuilder.GetUserAgent(request.UseSimplifiedUserAgent));
|
requestMessage.Headers.UserAgent.ParseAdd(_userAgentBuilder.GetUserAgent(request.UseSimplifiedUserAgent));
|
||||||
requestMessage.Headers.ConnectionClose = !request.ConnectionKeepAlive;
|
requestMessage.Headers.ConnectionClose = !request.ConnectionKeepAlive;
|
||||||
|
|
||||||
@ -122,7 +126,7 @@ public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
|
|||||||
|
|
||||||
headers.Add(responseMessage.Content.Headers.ToNameValueCollection());
|
headers.Add(responseMessage.Content.Headers.ToNameValueCollection());
|
||||||
|
|
||||||
return new HttpResponse(request, new HttpHeader(headers), data, responseMessage.StatusCode);
|
return new HttpResponse(request, new HttpHeader(headers), data, responseMessage.StatusCode, responseMessage.Version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +163,8 @@ protected virtual System.Net.Http.HttpClient CreateHttpClient(HttpProxySettings
|
|||||||
|
|
||||||
var client = new System.Net.Http.HttpClient(handler)
|
var client = new System.Net.Http.HttpClient(handler)
|
||||||
{
|
{
|
||||||
|
DefaultRequestVersion = HttpVersion.Version20,
|
||||||
|
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower,
|
||||||
Timeout = Timeout.InfiniteTimeSpan
|
Timeout = Timeout.InfiniteTimeSpan
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,28 +9,31 @@ namespace NzbDrone.Common.Http
|
|||||||
{
|
{
|
||||||
public class HttpResponse
|
public class HttpResponse
|
||||||
{
|
{
|
||||||
private static readonly Regex RegexSetCookie = new Regex("^(.*?)=(.*?)(?:;|$)", RegexOptions.Compiled);
|
private static readonly Regex RegexSetCookie = new ("^(.*?)=(.*?)(?:;|$)", RegexOptions.Compiled);
|
||||||
|
|
||||||
public HttpResponse(HttpRequest request, HttpHeader headers, byte[] binaryData, HttpStatusCode statusCode = HttpStatusCode.OK)
|
public HttpResponse(HttpRequest request, HttpHeader headers, byte[] binaryData, HttpStatusCode statusCode = HttpStatusCode.OK, Version version = null)
|
||||||
{
|
{
|
||||||
Request = request;
|
Request = request;
|
||||||
Headers = headers;
|
Headers = headers;
|
||||||
ResponseData = binaryData;
|
ResponseData = binaryData;
|
||||||
StatusCode = statusCode;
|
StatusCode = statusCode;
|
||||||
|
Version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse(HttpRequest request, HttpHeader headers, string content, HttpStatusCode statusCode = HttpStatusCode.OK)
|
public HttpResponse(HttpRequest request, HttpHeader headers, string content, HttpStatusCode statusCode = HttpStatusCode.OK, Version version = null)
|
||||||
{
|
{
|
||||||
Request = request;
|
Request = request;
|
||||||
Headers = headers;
|
Headers = headers;
|
||||||
ResponseData = Headers.GetEncodingFromContentType().GetBytes(content);
|
ResponseData = Headers.GetEncodingFromContentType().GetBytes(content);
|
||||||
_content = content;
|
_content = content;
|
||||||
StatusCode = statusCode;
|
StatusCode = statusCode;
|
||||||
|
Version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpRequest Request { get; private set; }
|
public HttpRequest Request { get; private set; }
|
||||||
public HttpHeader Headers { get; private set; }
|
public HttpHeader Headers { get; private set; }
|
||||||
public HttpStatusCode StatusCode { get; private set; }
|
public HttpStatusCode StatusCode { get; private set; }
|
||||||
|
public Version Version { get; private set; }
|
||||||
public byte[] ResponseData { get; private set; }
|
public byte[] ResponseData { get; private set; }
|
||||||
|
|
||||||
private string _content;
|
private string _content;
|
||||||
@ -84,7 +87,7 @@ public Dictionary<string, string> GetCookies()
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var result = string.Format("Res: [{0}] {1}: {2}.{3} ({4} bytes)", Request.Method, Request.Url, (int)StatusCode, StatusCode, ResponseData?.Length ?? 0);
|
var result = $"Res: HTTP/{Version} [{Request.Method}] {Request.Url}: {(int)StatusCode}.{StatusCode} ({ResponseData?.Length ?? 0} bytes)";
|
||||||
|
|
||||||
if (HasHttpError && Headers.ContentType.IsNotNullOrWhiteSpace() && !Headers.ContentType.Equals("text/html", StringComparison.InvariantCultureIgnoreCase))
|
if (HasHttpError && Headers.ContentType.IsNotNullOrWhiteSpace() && !Headers.ContentType.Equals("text/html", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
@ -99,7 +102,7 @@ public class HttpResponse<T> : HttpResponse
|
|||||||
where T : new()
|
where T : new()
|
||||||
{
|
{
|
||||||
public HttpResponse(HttpResponse response)
|
public HttpResponse(HttpResponse response)
|
||||||
: base(response.Request, response.Headers, response.ResponseData, response.StatusCode)
|
: base(response.Request, response.Headers, response.ResponseData, response.StatusCode, response.Version)
|
||||||
{
|
{
|
||||||
Resource = Json.Deserialize<T>(response.Content);
|
Resource = Json.Deserialize<T>(response.Content);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user