re-added HTTP status code checking
This commit is contained in:
parent
01996113de
commit
10808b8114
|
@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.7)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
project (mastodon-cpp
|
project (mastodon-cpp
|
||||||
VERSION 0.2.12
|
VERSION 0.2.13
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||||
|
|
|
@ -93,7 +93,7 @@ If you use a debug build, you get more verbose error messages.
|
||||||
* [x] Implement all PUT calls
|
* [x] Implement all PUT calls
|
||||||
* [x] Implement all DELETE calls
|
* [x] Implement all DELETE calls
|
||||||
* Version 0.3.0
|
* Version 0.3.0
|
||||||
* [x] Handle HTTP statuses 301 & 302
|
* [ ] Handle HTTP statuses 301 & 302
|
||||||
* [x] Support registering as an application
|
* [x] Support registering as an application
|
||||||
* Later
|
* Later
|
||||||
* [ ] Asynchronous I/O
|
* [ ] Asynchronous I/O
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <curlpp/Easy.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 "macros.hpp"
|
#include "macros.hpp"
|
||||||
#include "mastodon-cpp.hpp"
|
#include "mastodon-cpp.hpp"
|
||||||
|
|
||||||
|
@ -64,6 +65,8 @@ const std::uint16_t API::http::request_sync(const method &meth,
|
||||||
"Connection: close",
|
"Connection: close",
|
||||||
"Authorization: Bearer " + _access_token
|
"Authorization: Bearer " + _access_token
|
||||||
});
|
});
|
||||||
|
request.setOpt<curlopts::FollowLocation>(true);
|
||||||
|
request.setOpt<curlopts::WriteStream>(&oss);
|
||||||
if (!formdata.empty())
|
if (!formdata.empty())
|
||||||
{
|
{
|
||||||
request.setOpt<curlopts::HttpPost>(formdata);
|
request.setOpt<curlopts::HttpPost>(formdata);
|
||||||
|
@ -87,8 +90,23 @@ const std::uint16_t API::http::request_sync(const method &meth,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
oss << request;
|
request.perform();
|
||||||
answer = oss.str();
|
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)
|
catch (curlpp::RuntimeError &e)
|
||||||
{
|
{
|
||||||
|
|
Reference in New Issue