mirror of
https://github.com/Jackett/Jackett.git
synced 2025-12-23 14:47:07 +01:00
httpclient: generate absolute redirect urls
This commit is contained in:
@@ -271,9 +271,11 @@ namespace Jackett.Common.Utils.Clients
|
||||
{
|
||||
var newUri = response.Headers.Location;
|
||||
|
||||
if (newUri == null && response.Headers.TryGetValues("Refresh", out var refreshHeaders))
|
||||
if (newUri == null)
|
||||
{
|
||||
var refreshHeader = refreshHeaders.FirstOrDefault();
|
||||
var refreshHeader = response.Headers.TryGetValues("Refresh", out var refreshHeaders)
|
||||
? refreshHeaders.FirstOrDefault()
|
||||
: null;
|
||||
|
||||
if (refreshHeader == null)
|
||||
{
|
||||
@@ -290,7 +292,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
return null;
|
||||
}
|
||||
|
||||
return newUri;
|
||||
return new Uri(response.RequestMessage.RequestUri, newUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
src/Jackett.Test/Common/Utils/UriFixture.cs
Normal file
36
src/Jackett.Test/Common/Utils/UriFixture.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Jackett.Test.Common.Utils
|
||||
{
|
||||
[TestFixture]
|
||||
public class UriFixture
|
||||
{
|
||||
[TestCase("abc://my_host.com:8080/root/api/")]
|
||||
[TestCase("abc://my_host.com:8080//root/api/")]
|
||||
[TestCase("abc://my_host.com:8080/root//api/")]
|
||||
[TestCase("abc://[::1]:8080/root//api/")]
|
||||
public void should_parse(string uri)
|
||||
{
|
||||
var newUri = new Uri(uri);
|
||||
newUri.AbsoluteUri.Should().Be(uri);
|
||||
}
|
||||
|
||||
[TestCase("abc://host.com:8080/root/file.xml", "relative/path", "abc://host.com:8080/root/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml?query=1#fragment", "relative/path", "abc://host.com:8080/root/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml?query=1#fragment", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api", "relative/path", "abc://host.com:8080/root/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "relative/path", "abc://host.com:8080/root/api/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "//otherhost.com/path", "abc://otherhost.com/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "abc://otherhost.com/api/path", "abc://otherhost.com/api/path")]
|
||||
public void should_combine_uri(string basePath, string relativePath, string expected)
|
||||
{
|
||||
var newUri = new Uri(new Uri(basePath), new Uri(relativePath, UriKind.RelativeOrAbsolute));
|
||||
newUri.AbsoluteUri.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user