1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-01-03 13:46:10 +00:00

httpclient: generate absolute redirect urls

This commit is contained in:
Bogdan 2024-10-14 20:00:31 +03:00
parent 0da89a4183
commit c773909ba6
2 changed files with 41 additions and 3 deletions

View file

@ -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);
}
}
}

View 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);
}
}
}