diff --git a/CMakeLists.txt b/CMakeLists.txt index b0c057b..8665766 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.7) include(GNUInstallDirs) project (mastodon-cpp - VERSION 0.2.12 + VERSION 0.2.13 LANGUAGES CXX ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") diff --git a/README.md b/README.md index 387084c..edf6a91 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ If you use a debug build, you get more verbose error messages. * [x] Implement all PUT calls * [x] Implement all DELETE calls * Version 0.3.0 - * [x] Handle HTTP statuses 301 & 302 + * [ ] Handle HTTP statuses 301 & 302 * [x] Support registering as an application * Later * [ ] Asynchronous I/O diff --git a/src/http_sync.cpp b/src/http_sync.cpp index cde4e23..4bbdde9 100644 --- a/src/http_sync.cpp +++ b/src/http_sync.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "macros.hpp" #include "mastodon-cpp.hpp" @@ -64,6 +65,8 @@ const std::uint16_t API::http::request_sync(const method &meth, "Connection: close", "Authorization: Bearer " + _access_token }); + request.setOpt(true); + request.setOpt(&oss); if (!formdata.empty()) { request.setOpt(formdata); @@ -87,8 +90,23 @@ const std::uint16_t API::http::request_sync(const method &meth, break; } - oss << request; - answer = oss.str(); + request.perform(); + std::uint16_t ret = curlpp::infos::ResponseCode::get(request); + ttdebug << "Response code: " << ret << '\n'; + 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; + } } catch (curlpp::RuntimeError &e) {