Fix archiving by extracting the Content-Location header.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f8a5f881f3
commit
c218c23f97
|
@ -85,7 +85,8 @@ namespace remwharead
|
||||||
string _uri;
|
string _uri;
|
||||||
|
|
||||||
//! Make a HTTP(S) request.
|
//! Make a HTTP(S) request.
|
||||||
const string make_request(const string &uri) const;
|
const string make_request(const string &uri,
|
||||||
|
bool archive = false) const;
|
||||||
|
|
||||||
//! Extract the title from an HTML page.
|
//! Extract the title from an HTML page.
|
||||||
const string extract_title(const string &html);
|
const string extract_title(const string &html);
|
||||||
|
|
|
@ -130,9 +130,11 @@ namespace remwharead
|
||||||
return { false, "Unknown error.", "", "", "" };
|
return { false, "Unknown error.", "", "", "" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const string URI::make_request(const string &uri) const
|
const string URI::make_request(const string &uri, bool archive) const
|
||||||
{
|
{
|
||||||
Poco::URI poco_uri(uri);
|
Poco::URI poco_uri(uri);
|
||||||
|
string method =
|
||||||
|
archive ? HTTPRequest::HTTP_HEAD : HTTPRequest::HTTP_GET;
|
||||||
string path = poco_uri.getPathAndQuery();
|
string path = poco_uri.getPathAndQuery();
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
{
|
{
|
||||||
|
@ -151,8 +153,7 @@ namespace remwharead
|
||||||
poco_uri.getPort());
|
poco_uri.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPRequest request(HTTPRequest::HTTP_GET, path,
|
HTTPRequest request(method, path, HTTPMessage::HTTP_1_1);
|
||||||
HTTPMessage::HTTP_1_1);
|
|
||||||
request.set("User-Agent", string("remwharead/") + global::version);
|
request.set("User-Agent", string("remwharead/") + global::version);
|
||||||
|
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
|
@ -180,7 +181,14 @@ namespace remwharead
|
||||||
case HTTPResponse::HTTP_OK:
|
case HTTPResponse::HTTP_OK:
|
||||||
{
|
{
|
||||||
string answer;
|
string answer;
|
||||||
StreamCopier::copyToString(rs, answer);
|
if (archive)
|
||||||
|
{
|
||||||
|
answer = response.get("Content-Location");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StreamCopier::copyToString(rs, answer);
|
||||||
|
}
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -586,12 +594,11 @@ namespace remwharead
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const string answer = make_request("https://web.archive.org/save/"
|
const string answer = make_request("https://web.archive.org/save/"
|
||||||
+ _uri);
|
+ _uri, true);
|
||||||
|
|
||||||
smatch match;
|
if (!answer.empty())
|
||||||
if (regex_search(answer, match, regex("Content-Location: (.+)\r")))
|
|
||||||
{
|
{
|
||||||
return { true, "", "https://web.archive.org" + match[1].str() };
|
return { true, "", "https://web.archive.org" + answer };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const Poco::Exception &e)
|
catch (const Poco::Exception &e)
|
||||||
|
|
Loading…
Reference in New Issue