mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-13 16:43:58 -07:00
Fixed: Now sends appropriate http Accept header to indexer.
This commit is contained in:
parent
525f1aa9dd
commit
b3f086fe93
3 changed files with 87 additions and 10 deletions
|
@ -25,7 +25,9 @@ namespace NzbDrone.Common.Http
|
|||
public HttpClient(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_userAgent = String.Format("NzbDrone {0}", BuildInfo.Version);
|
||||
_userAgent = String.Format("NzbDrone/{0} ({1} {2})",
|
||||
BuildInfo.Version,
|
||||
OsInfo.Os, OsInfo.Version.ToString(2));
|
||||
ServicePointManager.DefaultConnectionLimit = 12;
|
||||
}
|
||||
|
||||
|
@ -42,6 +44,7 @@ namespace NzbDrone.Common.Http
|
|||
|
||||
webRequest.Credentials = request.NetworkCredential;
|
||||
webRequest.Method = request.Method.ToString();
|
||||
webRequest.UserAgent = _userAgent;
|
||||
webRequest.KeepAlive = false;
|
||||
|
||||
if (!RuntimeInfoBase.IsProduction)
|
||||
|
@ -51,6 +54,11 @@ namespace NzbDrone.Common.Http
|
|||
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
|
||||
if (request.Headers != null)
|
||||
{
|
||||
AddRequestHeaders(webRequest, request.Headers);
|
||||
}
|
||||
|
||||
if (!request.Body.IsNullOrWhiteSpace())
|
||||
{
|
||||
var bytes = new byte[request.Body.Length * sizeof(char)];
|
||||
|
@ -154,5 +162,55 @@ namespace NzbDrone.Common.Http
|
|||
return Execute(request);
|
||||
}
|
||||
|
||||
protected virtual void AddRequestHeaders(HttpWebRequest webRequest, HttpHeader headers)
|
||||
{
|
||||
foreach (var header in headers)
|
||||
{
|
||||
switch (header.Key)
|
||||
{
|
||||
case "Accept":
|
||||
webRequest.Accept = header.Value.ToString();
|
||||
break;
|
||||
case "Connection":
|
||||
webRequest.Connection = header.Value.ToString();
|
||||
break;
|
||||
case "Content-Length":
|
||||
webRequest.ContentLength = Convert.ToInt64(header.Value);
|
||||
break;
|
||||
case "Content-Type":
|
||||
webRequest.ContentType = header.Value.ToString();
|
||||
break;
|
||||
case "Date":
|
||||
webRequest.Date = (DateTime)header.Value;
|
||||
break;
|
||||
case "Expect":
|
||||
webRequest.Expect = header.Value.ToString();
|
||||
break;
|
||||
case "Host":
|
||||
webRequest.Host = header.Value.ToString();
|
||||
break;
|
||||
case "If-Modified-Since":
|
||||
webRequest.IfModifiedSince = (DateTime)header.Value;
|
||||
break;
|
||||
case "Range":
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case "Referer":
|
||||
webRequest.Referer = header.Value.ToString();
|
||||
break;
|
||||
case "Transfer-Encoding":
|
||||
webRequest.TransferEncoding = header.Value.ToString();
|
||||
break;
|
||||
case "User-Agent":
|
||||
throw new NotSupportedException("User-Agent other than NzbDrone not allowed.");
|
||||
case "Proxy-Connection":
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
default:
|
||||
webRequest.Headers.Add(header.Key, header.Value.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue