Make a HTTP request.
73 _stream_cancelled =
false;
74 _curl_buffer_headers.clear();
75 _curl_buffer_body.clear();
80 case http_method::GET:
82 add_parameters_to_uri(uri, parameters);
84 curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
88 case http_method::POST:
90 if (parameters.empty())
93 curl_easy_setopt(_connection, CURLOPT_POST, 1L);
97 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
99 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
104 case http_method::PATCH:
106 if (!parameters.empty())
108 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
110 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
114 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
115 if (code != CURLE_OK)
117 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
122 case http_method::PUT:
124 if (!parameters.empty())
126 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
128 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
132 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PUT");
133 if (code != CURLE_OK)
135 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
140 case http_method::DELETE:
142 if (!parameters.empty())
144 curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
146 curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
150 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
151 if (code != CURLE_OK)
153 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
159 debuglog <<
"Making request to: " << uri <<
'\n';
162 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
163 if (code != CURLE_OK)
165 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
169 code = curl_easy_perform(_connection);
171 || (code == CURLE_ABORTED_BY_CALLBACK && _stream_cancelled))
175 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
176 answer.http_status = static_cast<uint16_t>(http_status);
177 debuglog <<
"HTTP status code: " << http_status <<
'\n';
179 answer.headers = _curl_buffer_headers;
180 answer.body = _curl_buffer_body;
184 answer.curl_error_code = static_cast<uint8_t>(code);
185 answer.error_message = _curl_buffer_error;
186 debuglog <<
"libcurl error: " << code <<
'\n';
187 debuglog << _curl_buffer_error <<
'\n';