Make a HTTP request.
70 _stream_cancelled =
false;
71 _curl_buffer_headers.clear();
72 _curl_buffer_body.clear();
77 case http_method::GET:
79 add_parameters_to_uri(uri, parameters);
81 curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
85 case http_method::POST:
87 if (parameters.empty())
90 curl_easy_setopt(_connection, CURLOPT_POST, 1L);
94 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
96 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
101 case http_method::PATCH:
103 if (!parameters.empty())
105 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
107 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
111 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
112 if (code != CURLE_OK)
114 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
119 case http_method::PUT:
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,
"PUT");
130 if (code != CURLE_OK)
132 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
137 case http_method::DELETE:
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,
"DELETE");
148 if (code != CURLE_OK)
150 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
156 debuglog <<
"Making request to: " << uri <<
'\n';
159 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
160 if (code != CURLE_OK)
162 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
166 code = curl_easy_perform(_connection);
168 || (code == CURLE_ABORTED_BY_CALLBACK && _stream_cancelled))
172 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
173 answer.http_status = static_cast<uint16_t>(http_status);
174 debuglog <<
"HTTP status code: " << http_status <<
'\n';
176 answer.headers = _curl_buffer_headers;
177 answer.body = _curl_buffer_body;
181 answer.curl_error_code = static_cast<uint8_t>(code);
182 answer.error_message = _curl_buffer_error;
183 debuglog <<
"libcurl error: " << code <<
'\n';
184 debuglog << _curl_buffer_error <<
'\n';