You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Common/Http/HttpRequest.cs

68 lines
2.1 KiB

10 years ago
using System;
using System.Collections.Generic;
using System.Linq;
10 years ago
using System.Net;
using System.Text;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
10 years ago
namespace NzbDrone.Common.Http
{
public class HttpRequest
{
public HttpRequest(string uri, HttpAccept httpAccept = null)
10 years ago
{
UrlBuilder = new UriBuilder(uri);
10 years ago
Headers = new HttpHeader();
AllowAutoRedirect = true;
Cookies = new Dictionary<string, string>();
if (!RuntimeInfoBase.IsProduction)
{
AllowAutoRedirect = false;
}
if (httpAccept != null)
{
Headers.Accept = httpAccept.Value;
}
10 years ago
}
public UriBuilder UrlBuilder { get; private set; }
public Uri Url { get { return UrlBuilder.Uri; } }
10 years ago
public HttpMethod Method { get; set; }
public HttpHeader Headers { get; set; }
public byte[] ContentData { get; set; }
public string ContentSummary { get; set; }
10 years ago
public NetworkCredential NetworkCredential { get; set; }
public bool SuppressHttpError { get; set; }
public bool AllowAutoRedirect { get; set; }
public Dictionary<string, string> Cookies { get; private set; }
public bool StoreResponseCookie { get; set; }
public TimeSpan RequestTimeout { get; set; }
public TimeSpan RateLimit { get; set; }
10 years ago
public override string ToString()
{
if (ContentSummary == null)
10 years ago
{
return string.Format("Req: [{0}] {1}", Method, Url);
}
else
10 years ago
{
return string.Format("Req: [{0}] {1}: {2}", Method, Url, ContentSummary);
10 years ago
}
}
public void SetContent(byte[] data)
{
ContentData = data;
}
public void SetContent(string data)
{
var encoding = HttpHeader.GetEncodingFromContentType(Headers.ContentType);
ContentData = encoding.GetBytes(data);
}
10 years ago
}
}