From 8e4d70985da1c0dc4658a461cafbb5ba973fe56b Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 18 May 2019 07:54:22 +0200 Subject: [PATCH] Added set_curlpp_options() to set common curlpp options. --- src/uri.cpp | 19 ++++++++++--------- src/uri.hpp | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/uri.cpp b/src/uri.cpp index ca5763e..4a01304 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -48,10 +47,7 @@ const html_extract URI::get() { std::ostringstream oss; curlpp::Easy request; - request.setOpt(string("remwharead/") - + global::version); - request.setOpt({ "Connection: close" }); - request.setOpt(true); + set_curlpp_options(request); request.setOpt(_uri); request.setOpt(&oss); request.perform(); @@ -80,6 +76,14 @@ const html_extract URI::get() return { "", "", "" }; } +void URI::set_curlpp_options(curlpp::Easy &request) +{ + request.setOpt(string("remwharead/") + + global::version); + request.setOpt({ "Connection: close" }); + request.setOpt(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(string("remwharead/") - + global::version); - request.setOpt({ "Connection: close" }); - request.setOpt(true); + set_curlpp_options(request); request.setOpt("https://web.archive.org/save/" + _uri); request.setOpt(&oss); request.setOpt(true); // Make a HEAD request. diff --git a/src/uri.hpp b/src/uri.hpp index 3217013..f76b305 100644 --- a/src/uri.hpp +++ b/src/uri.hpp @@ -18,6 +18,7 @@ #define REMWHAREAD_URI_HPP #include +#include 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);