# HG changeset patch # User František Kučera # Date 1647647387 -3600 # Node ID e41abdd36ff1521a06bd07306f32fa353c2a4e4d # Parent 18f4f7e93c4815871d7ac3057b83a91d0ecd399e request methods support in HTTPClient diff -r 18f4f7e93c48 -r e41abdd36ff1 src/HTTPClient.cpp --- a/src/HTTPClient.cpp Tue Mar 15 23:58:27 2022 +0100 +++ b/src/HTTPClient.cpp Sat Mar 19 00:49:47 2022 +0100 @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -130,7 +131,17 @@ const HTTPClient::Response HTTPClient::exchange(const Request& request) { HTTPClient::Response response; - // TODO: set request method + // set request method + std::string method; + if (request.method == Method::DELETE) method = "DELETE"; + else if (request.method == Method::GET) method = "GET"; + else if (request.method == Method::HEAD) method = "HEAD"; + else if (request.method == Method::PATCH) method = "PATCH"; + else if (request.method == Method::POST) method = "POST"; + else if (request.method == Method::PUT) method = "PUT"; + else throw std::invalid_argument("Unsupported HTTP method: " + std::to_string((int) request.method)); + curl_easy_setopt(impl->curl, CURLOPT_CUSTOMREQUEST, method.c_str()); + if (request.method == Method::HEAD) curl_easy_setopt(impl->curl, CURLOPT_NOBODY, 1L); // set URL curl_easy_setopt(impl->curl, CURLOPT_URL, request.url.c_str());