Make a HTTP request.
83 _stream_cancelled =
false;
84 _curl_buffer_headers.clear();
85 _curl_buffer_body.clear();
87 CURLcode code{CURLE_OK};
90 case http_method::GET:
92 add_parameters_to_uri(uri, parameters);
94 curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
98 case http_method::POST:
100 if (parameters.empty())
103 curl_easy_setopt(_connection, CURLOPT_POST, 1L);
107 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
109 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
114 case http_method::PATCH:
116 if (!parameters.empty())
118 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
120 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
124 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
125 if (code != CURLE_OK)
127 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
132 case http_method::PUT:
134 if (!parameters.empty())
136 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
138 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
142 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PUT");
143 if (code != CURLE_OK)
145 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
150 case http_method::DELETE:
152 if (!parameters.empty())
154 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
156 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
160 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
161 if (code != CURLE_OK)
163 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
169 debuglog <<
"Making request to: " << uri <<
'\n';
172 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
173 if (code != CURLE_OK)
175 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
179 code = curl_easy_perform(_connection);
181 || (code == CURLE_ABORTED_BY_CALLBACK && _stream_cancelled))
185 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
186 answer.http_status =
static_cast<uint16_t
>(http_status);
187 debuglog <<
"HTTP status code: " << http_status <<
'\n';
189 answer.headers = _curl_buffer_headers;
190 answer.body = _curl_buffer_body;
194 answer.curl_error_code =
static_cast<uint8_t
>(code);
195 answer.error_message = _curl_buffer_error;
196 debuglog <<
"libcurl error: " << code <<
'\n';
197 debuglog << _curl_buffer_error <<
'\n';