mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Updated URL rewriter to handle torcache Referer weirdness.
This commit is contained in:
parent
cf25097cd1
commit
958b294152
@ -23,6 +23,16 @@ public void should_remove_query_params_from_torcache_request()
|
|||||||
newRequest.Url.AbsoluteUri.Should().Be("http://torcache.net/download/123.torrent");
|
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://site.com/download?url=torcache.net&blaat=1")]
|
||||||
[TestCase("http://torcache.net.com/download?url=123")]
|
[TestCase("http://torcache.net.com/download?url=123")]
|
||||||
public void should_not_remove_query_params_from_other_requests(string url)
|
public void should_not_remove_query_params_from_other_requests(string url)
|
||||||
|
@ -11,9 +11,12 @@ public class TorCacheHttpRequestInterceptor : IHttpRequestInterceptor
|
|||||||
{
|
{
|
||||||
public HttpRequest PreRequest(HttpRequest request)
|
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.UriBuilder.Query = string.Empty;
|
||||||
|
request.Headers.Add("Referer", request.Url.Scheme + @"://torcache.net/");
|
||||||
}
|
}
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
|
Loading…
Reference in New Issue
Block a user