Make a HTTP request.
88 _stream_cancelled =
false;
89 _curl_buffer_headers.clear();
90 _curl_buffer_body.clear();
95 case http_method::GET:
97 add_parameters_to_uri(uri, parameters);
99 curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
103 case http_method::POST:
105 if (parameters.empty())
108 curl_easy_setopt(_connection, CURLOPT_POST, 1L);
112 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
114 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
119 case http_method::PATCH:
121 if (!parameters.empty())
123 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
125 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
129 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
130 if (code != CURLE_OK)
132 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
137 case http_method::PUT:
139 if (!parameters.empty())
141 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
143 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
147 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PUT");
148 if (code != CURLE_OK)
150 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
155 case http_method::DELETE:
157 if (!parameters.empty())
159 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
161 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
165 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
166 if (code != CURLE_OK)
168 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
174 debuglog <<
"Making request to: " << uri <<
'\n';
177 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
178 if (code != CURLE_OK)
180 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
184 code = curl_easy_perform(_connection);
186 || (code == CURLE_ABORTED_BY_CALLBACK && _stream_cancelled))
190 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
191 answer.http_status =
static_cast<uint16_t
>(http_status);
192 debuglog <<
"HTTP status code: " << http_status <<
'\n';
194 answer.headers = _curl_buffer_headers;
195 answer.body = _curl_buffer_body;
199 answer.curl_error_code =
static_cast<uint8_t
>(code);
200 answer.error_message = _curl_buffer_error;
201 debuglog <<
"libcurl error: " << code <<
'\n';
202 debuglog << _curl_buffer_error <<
'\n';