Treat permanent redirects after temporary redirects as temporary.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
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:
parent
94ca8bffaf
commit
e8ac4869b1
|
@ -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:
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user