mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-14 00:53:57 -07:00
HttpClient
This commit is contained in:
parent
3a287bf7e7
commit
2c1d3339d0
55 changed files with 995 additions and 582 deletions
40
src/NzbDrone.Common/Http/HttpRequestBuilder.cs
Normal file
40
src/NzbDrone.Common/Http/HttpRequestBuilder.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class HttpRequestBuilder
|
||||
{
|
||||
public Uri BaseUri { get; private set; }
|
||||
public bool SupressHttpError { get; set; }
|
||||
public NetworkCredential NetworkCredential { get; set; }
|
||||
|
||||
public Action<HttpRequest> PostProcess { get; set; }
|
||||
|
||||
public HttpRequestBuilder(string baseUri)
|
||||
{
|
||||
BaseUri = new Uri(baseUri);
|
||||
}
|
||||
|
||||
public virtual HttpRequest Build(string path)
|
||||
{
|
||||
if (BaseUri.ToString().EndsWith("/"))
|
||||
{
|
||||
path = path.TrimStart('/');
|
||||
}
|
||||
|
||||
var request = new HttpRequest(BaseUri + path)
|
||||
{
|
||||
SuppressHttpError = SupressHttpError,
|
||||
NetworkCredential = NetworkCredential
|
||||
};
|
||||
|
||||
if (PostProcess != null)
|
||||
{
|
||||
PostProcess(request);
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue