Added set_curlpp_options() to set common curlpp options.
This commit is contained in:
parent
41cae64a04
commit
8e4d70985d
19
src/uri.cpp
19
src/uri.cpp
|
@ -21,7 +21,6 @@
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <curlpp/cURLpp.hpp>
|
#include <curlpp/cURLpp.hpp>
|
||||||
#include <curlpp/Easy.hpp>
|
|
||||||
#include <curlpp/Options.hpp>
|
#include <curlpp/Options.hpp>
|
||||||
#include <curlpp/Exception.hpp>
|
#include <curlpp/Exception.hpp>
|
||||||
#include <curlpp/Infos.hpp>
|
#include <curlpp/Infos.hpp>
|
||||||
|
@ -48,10 +47,7 @@ const html_extract URI::get()
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
curlpp::Easy request;
|
curlpp::Easy request;
|
||||||
request.setOpt<curlopts::UserAgent>(string("remwharead/")
|
set_curlpp_options(request);
|
||||||
+ global::version);
|
|
||||||
request.setOpt<curlopts::HttpHeader>({ "Connection: close" });
|
|
||||||
request.setOpt<curlopts::FollowLocation>(true);
|
|
||||||
request.setOpt<curlopts::Url>(_uri);
|
request.setOpt<curlopts::Url>(_uri);
|
||||||
request.setOpt<curlopts::WriteStream>(&oss);
|
request.setOpt<curlopts::WriteStream>(&oss);
|
||||||
request.perform();
|
request.perform();
|
||||||
|
@ -80,6 +76,14 @@ const html_extract URI::get()
|
||||||
return { "", "", "" };
|
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 string URI::extract_title(const string &html)
|
||||||
{
|
{
|
||||||
const regex re_htmlfile("\\.(.?html?|xml|rss)$");
|
const regex re_htmlfile("\\.(.?html?|xml|rss)$");
|
||||||
|
@ -474,10 +478,7 @@ const string URI::archive()
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
curlpp::Easy request;
|
curlpp::Easy request;
|
||||||
request.setOpt<curlopts::UserAgent>(string("remwharead/")
|
set_curlpp_options(request);
|
||||||
+ global::version);
|
|
||||||
request.setOpt<curlopts::HttpHeader>({ "Connection: close" });
|
|
||||||
request.setOpt<curlopts::FollowLocation>(true);
|
|
||||||
request.setOpt<curlopts::Url>("https://web.archive.org/save/" + _uri);
|
request.setOpt<curlopts::Url>("https://web.archive.org/save/" + _uri);
|
||||||
request.setOpt<curlopts::WriteStream>(&oss);
|
request.setOpt<curlopts::WriteStream>(&oss);
|
||||||
request.setOpt<curlopts::NoBody>(true); // Make a HEAD request.
|
request.setOpt<curlopts::NoBody>(true); // Make a HEAD request.
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#define REMWHAREAD_URI_HPP
|
#define REMWHAREAD_URI_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <curlpp/Easy.hpp>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
string _uri;
|
string _uri;
|
||||||
|
|
||||||
|
void set_curlpp_options(curlpp::Easy &request);
|
||||||
const string extract_title(const string &html);
|
const string extract_title(const string &html);
|
||||||
const string extract_description(const string &html);
|
const string extract_description(const string &html);
|
||||||
const string strip_html(const string &html);
|
const string strip_html(const string &html);
|
||||||
|
|
Loading…
Reference in New Issue