Treat permanent redirects after temporary redirects as temporary.
continuous-integration/drone/push Build is passing Details

Example:
http://example.com/ returns 302 with Location: http://example.com/1
http://example.com/1 returns 301 with Location: http://example.com/2

http://example.com/ will not be overwritten in the config file.
This commit is contained in:
tastytea 2019-12-29 00:41:14 +01:00
parent 94ca8bffaf
commit e8ac4869b1
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 20 additions and 4 deletions

View File

@ -61,7 +61,7 @@ Document::~Document()
RestClient::disable(); RestClient::disable();
} }
void Document::download(const string &uri) void Document::download(const string &uri, const bool temp_redirect)
{ {
RestClient::Connection connection{uri}; RestClient::Connection connection{uri};
connection.SetUserAgent(string("mastorss/").append(version)); connection.SetUserAgent(string("mastorss/").append(version));
@ -80,6 +80,10 @@ void Document::download(const string &uri)
case 301: case 301:
case 308: case 308:
{ {
if (temp_redirect)
{
goto temporary_redirect;
}
_profiledata.feedurl = extract_location(response.headers); _profiledata.feedurl = extract_location(response.headers);
if (_profiledata.feedurl.empty()) if (_profiledata.feedurl.empty())
{ {
@ -96,6 +100,7 @@ void Document::download(const string &uri)
case 303: case 303:
case 307: case 307:
{ {
temporary_redirect:
const string newuri{extract_location(response.headers)}; const string newuri{extract_location(response.headers)};
if (newuri.empty()) if (newuri.empty())
{ {
@ -104,7 +109,7 @@ void Document::download(const string &uri)
BOOST_LOG_TRIVIAL(debug) << "Feed has new location (temporary): " BOOST_LOG_TRIVIAL(debug) << "Feed has new location (temporary): "
<< _profiledata.feedurl; << _profiledata.feedurl;
download(newuri); download(newuri, true);
break; break;
} }
case -1: case -1:

View File

@ -63,8 +63,6 @@ public:
list<Item> new_items; list<Item> new_items;
void download();
void download(const string &uri);
void parse(); void parse();
private: private:
@ -73,6 +71,19 @@ private:
string _raw_doc; string _raw_doc;
list<string> _watchwords; list<string> _watchwords;
void download();
/*!
* @brief Download document.
*
* @param uri The URI to download.
* @param temp_redirect `true` if this is an temporary redirect.
*
* The argument `temp_redirect` is there for cases where the original URI
* is redirected temporarily, and the new URI is redirected permanently.
*
* @since 0.10.0
*/
void download(const string &uri, const bool temp_redirect = false);
void parse_rss(const pt::ptree &tree); void parse_rss(const pt::ptree &tree);
[[nodiscard]] [[nodiscard]]
string remove_html(string html) const; string remove_html(string html) const;