|
|
|
@ -9,28 +9,31 @@ namespace NzbDrone.Common.Http
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
Headers = headers;
|
|
|
|
|
ResponseData = binaryData;
|
|
|
|
|
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;
|
|
|
|
|
Headers = headers;
|
|
|
|
|
ResponseData = Headers.GetEncodingFromContentType().GetBytes(content);
|
|
|
|
|
_content = content;
|
|
|
|
|
StatusCode = statusCode;
|
|
|
|
|
Version = version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HttpRequest Request { get; private set; }
|
|
|
|
|
public HttpHeader Headers { get; private set; }
|
|
|
|
|
public HttpStatusCode StatusCode { get; private set; }
|
|
|
|
|
public Version Version { get; private set; }
|
|
|
|
|
public byte[] ResponseData { get; private set; }
|
|
|
|
|
|
|
|
|
|
private string _content;
|
|
|
|
@ -84,7 +87,7 @@ namespace NzbDrone.Common.Http
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
@ -99,7 +102,7 @@ namespace NzbDrone.Common.Http
|
|
|
|
|
where T : new()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|