mirror of https://github.com/lidarr/Lidarr
Updated URL rewriter to handle torcache Referer weirdness.
This commit is contained in:
parent
cf25097cd1
commit
958b294152
|
@ -23,6 +23,16 @@ namespace NzbDrone.Core.Test.Http
|
|||
newRequest.Url.AbsoluteUri.Should().Be("http://torcache.net/download/123.torrent");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_add_referrer_torcache_request()
|
||||
{
|
||||
var request = new HttpRequest("http://torcache.net/download/123.torrent?title=something");
|
||||
|
||||
var newRequest = Subject.PreRequest(request);
|
||||
|
||||
newRequest.Headers.Should().Contain("Referer", "http://torcache.net/");
|
||||
}
|
||||
|
||||
[TestCase("http://site.com/download?url=torcache.net&blaat=1")]
|
||||
[TestCase("http://torcache.net.com/download?url=123")]
|
||||
public void should_not_remove_query_params_from_other_requests(string url)
|
||||
|
|
|
@ -11,9 +11,12 @@ namespace NzbDrone.Core.Http
|
|||
{
|
||||
public HttpRequest PreRequest(HttpRequest request)
|
||||
{
|
||||
if (request.Url.Host == "torcache.net" && request.UriBuilder.Query.IsNotNullOrWhiteSpace())
|
||||
// torcache behaves strangely when it has query params and/or no Referer or browser User-Agent.
|
||||
// It's a bit vague, and we don't need the query params. So we remove the query params and set a Referer to be safe.
|
||||
if (request.Url.Host == "torcache.net")
|
||||
{
|
||||
request.UriBuilder.Query = string.Empty;
|
||||
request.Headers.Add("Referer", request.Url.Scheme + @"://torcache.net/");
|
||||
}
|
||||
|
||||
return request;
|
||||
|
|
Loading…
Reference in New Issue