Added set_curlpp_options() to set common curlpp options.

This commit is contained in:
tastytea 2019-05-18 07:54:22 +02:00
parent 41cae64a04
commit 8e4d70985d
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 12 additions and 9 deletions

View File

@ -21,7 +21,6 @@
#include <locale>
#include <codecvt>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>
#include <curlpp/Infos.hpp>
@ -48,10 +47,7 @@ const html_extract URI::get()
{
std::ostringstream oss;
curlpp::Easy request;
request.setOpt<curlopts::UserAgent>(string("remwharead/")
+ global::version);
request.setOpt<curlopts::HttpHeader>({ "Connection: close" });
request.setOpt<curlopts::FollowLocation>(true);
set_curlpp_options(request);
request.setOpt<curlopts::Url>(_uri);
request.setOpt<curlopts::WriteStream>(&oss);
request.perform();
@ -80,6 +76,14 @@ const html_extract URI::get()
return { "", "", "" };
}
void URI::set_curlpp_options(curlpp::Easy &request)
{
request.setOpt<curlopts::UserAgent>(string("remwharead/")
+ global::version);
request.setOpt<curlopts::HttpHeader>({ "Connection: close" });
request.setOpt<curlopts::FollowLocation>(true);
}
const string URI::extract_title(const string &html)
{
const regex re_htmlfile("\\.(.?html?|xml|rss)$");
@ -474,10 +478,7 @@ const string URI::archive()
{
std::ostringstream oss;
curlpp::Easy request;
request.setOpt<curlopts::UserAgent>(string("remwharead/")
+ global::version);
request.setOpt<curlopts::HttpHeader>({ "Connection: close" });
request.setOpt<curlopts::FollowLocation>(true);
set_curlpp_options(request);
request.setOpt<curlopts::Url>("https://web.archive.org/save/" + _uri);
request.setOpt<curlopts::WriteStream>(&oss);
request.setOpt<curlopts::NoBody>(true); // Make a HEAD request.

View File

@ -18,6 +18,7 @@
#define REMWHAREAD_URI_HPP
#include <string>
#include <curlpp/Easy.hpp>
using std::string;
@ -41,6 +42,7 @@ public:
protected:
string _uri;
void set_curlpp_options(curlpp::Easy &request);
const string extract_title(const string &html);
const string extract_description(const string &html);
const string strip_html(const string &html);