diff --git a/src/http.cpp b/src/http.cpp index 4ef8bfc..83f46c7 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "mastorss.hpp" using std::string; @@ -31,6 +32,11 @@ using std::cerr; namespace curlopts = curlpp::options; +void curlpp_init() +{ + curlpp::initialize(); +} + const std::uint16_t http_get(const string &feedurl, string &answer, const string &useragent) { try @@ -43,10 +49,24 @@ const std::uint16_t http_get(const string &feedurl, string &answer, const string { "Connection: close", }); + request.setOpt(true); + request.setOpt(&oss); - - oss << request; - answer = oss.str(); + request.perform(); + std::uint16_t ret = curlpp::infos::ResponseCode::get(request); + if (ret == 200 || ret == 302 || ret == 307) + { // OK or Found or Temporary Redirect + answer = oss.str(); + } + else if (ret == 301 || ret == 308) + { // Moved Permanently or Permanent Redirect + // FIXME: The new URL should be passed back somehow + answer = oss.str(); + } + else + { + return ret; + } return 0; } diff --git a/src/mastorss.cpp b/src/mastorss.cpp index f82b2e6..dfe3801 100644 --- a/src/mastorss.cpp +++ b/src/mastorss.cpp @@ -242,11 +242,12 @@ int main(int argc, char *argv[]) std::uint16_t ret; read_config(config, profile, instance, access_token, feedurl); + curlpp_init(); string answer; string last_entry = config.get(profile + ".last_entry", ""); std::vector entries; - //FIXME: User-Agent + ret = http_get(feedurl, answer, "mastorss/" + (string)global::version); if (ret != 0) { diff --git a/src/mastorss.hpp b/src/mastorss.hpp index 5d5cfac..d80603f 100644 --- a/src/mastorss.hpp +++ b/src/mastorss.hpp @@ -15,5 +15,6 @@ std::vector parse_website(const string &profile, const string &xml); // http.cpp const std::uint16_t http_get(const string &feedurl, string &answer, const string &useragent = ""); +void curlpp_init(); #endif // mastorss_HPP