--- 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 <http://www.gnu.org/licenses/>.
*/
+#include <string>
#include <sstream>
#include <iostream>
@@ -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());