arminreiter/FeedReader

AutoRedirect: Also handle relative location path correctly

andreasld97 opened this issue · 0 comments

Hi,

when using autoRedirect there is a problem with relative urls, because there are some feeds that
are using relative urls in the Location-Header since this is also valid:

https://www.tagesschau.de/xml/rss2/

The problem is that only AbsoluteUri will be used for the redirect:

So for relative urls an System.InvalidOperationException will be thrown here:

url = response.Headers?.Location?.AbsoluteUri ?? url;

(https://github.com/arminreiter/FeedReader/blob/master/FeedReader/Helpers.cs#L67-L76)

A fix for this problem could be done like this (I am not entirely sure if that is the correct way to get the absolute url though):

if (response.Headers?.Location?.IsAbsoluteUri == true)
{
    url = response.Headers?.Location?.AbsoluteUri;
}
else
{
    var uri = new Uri(url);
    url = uri.GetLeftPart(UriPartial.Authority) + response.Headers?.Location;           
}