Make a HTTP request.
80 _stream_cancelled =
false;
81 _curl_buffer_headers.clear();
82 _curl_buffer_body.clear();
87 case http_method::GET:
89 add_parameters_to_uri(uri, parameters);
91 curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
95 case http_method::POST:
97 if (parameters.empty())
100 curl_easy_setopt(_connection, CURLOPT_POST, 1L);
104 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
106 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
111 case http_method::PATCH:
113 if (!parameters.empty())
115 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
117 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
121 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
122 if (code != CURLE_OK)
124 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
129 case http_method::PUT:
131 if (!parameters.empty())
133 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
135 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
139 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PUT");
140 if (code != CURLE_OK)
142 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
147 case http_method::DELETE:
149 if (!parameters.empty())
151 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
153 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
157 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
158 if (code != CURLE_OK)
160 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
166 debuglog <<
"Making request to: " << uri <<
'\n';
169 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
170 if (code != CURLE_OK)
172 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
176 code = curl_easy_perform(_connection);
178 || (code == CURLE_ABORTED_BY_CALLBACK && _stream_cancelled))
182 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
183 answer.http_status = static_cast<uint16_t>(http_status);
184 debuglog <<
"HTTP status code: " << http_status <<
'\n';
186 answer.headers = _curl_buffer_headers;
187 answer.body = _curl_buffer_body;
191 answer.curl_error_code = static_cast<uint8_t>(code);
192 answer.error_message = _curl_buffer_error;
193 debuglog <<
"libcurl error: " << code <<
'\n';
194 debuglog << _curl_buffer_error <<
'\n';