diff options
author | tastytea | 2020-01-11 16:23:28 +0100 |
---|---|---|
committer | tastytea | 2020-01-11 16:24:06 +0100 |
commit | 5c61d6fd27fa6a9cf766f603cbc12e04acc7c887 (patch) | |
tree | 743d837211f32eb68fd5a4d59002283b2518411d | |
parent | 03b097c6a6f47a875f74f84f4a114e2820d07039 (diff) | |
download | mastodonpp-5c61d6fd27fa6a9cf766f603cbc12e04acc7c887.tar mastodonpp-5c61d6fd27fa6a9cf766f603cbc12e04acc7c887.tar.gz mastodonpp-5c61d6fd27fa6a9cf766f603cbc12e04acc7c887.zip |
Add support for DELETE requests.
-rw-r--r-- | include/connection.hpp | 26 | ||||
-rw-r--r-- | src/connection.cpp | 7 | ||||
-rw-r--r-- | src/curl_wrapper.cpp | 8 |
3 files changed, 41 insertions, 0 deletions
diff --git a/include/connection.hpp b/include/connection.hpp index 536123e..761f777 100644 --- a/include/connection.hpp +++ b/include/connection.hpp @@ -214,6 +214,32 @@ public: } /*! + * @brief Make a HTTP DELETE call with parameters. + * + * @param endpoint Endpoint as API::endpoint_type or `std::string_view`. + * @param parameters A map of parameters. + * + * + * @since 0.2.0 + */ + [[nodiscard]] + answer_type del(const endpoint_variant &endpoint, + const parametermap ¶meters); + + /*! + * @brief Make a HTTP DELETE call. + * + * @param endpoint Endpoint as API::endpoint_type or `std::string_view`. + * + * @since 0.2.0 + */ + [[nodiscard]] + inline answer_type del(const endpoint_variant &endpoint) + { + return del(endpoint, {}); + } + + /*! * @brief Copy new stream contents and delete the “original”. * * Note that the last event is not necessarily complete, it could happen diff --git a/src/connection.cpp b/src/connection.cpp index 9cde7d3..3a10d14 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -75,6 +75,13 @@ answer_type Connection::put(const endpoint_variant &endpoint, endpoint_to_uri(endpoint), parameters); } +answer_type Connection::del(const endpoint_variant &endpoint, + const parametermap ¶meters) +{ + return make_request(http_method::DELETE, + endpoint_to_uri(endpoint), parameters); +} + string Connection::get_new_stream_contents() { buffer_mutex.lock(); diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index 7b2b352..6b62389 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -139,8 +139,16 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri, } case http_method::DELETE: { + if (!parameters.empty()) + { + curl_mime *mime{parameters_to_curl_mime(uri, parameters)}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + code = curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime); + } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST, "DELETE"); + break; } } |