Handles the details of network connections.
More...
#include <mastodonpp/curl_wrapper.hpp>
Handles the details of network connections.
You don't need to use this.
- Since
- 0.1.0
◆ CURLWrapper() [1/3]
mastodonpp::CURLWrapper::CURLWrapper |
( |
| ) |
|
Initializes curl and sets up connection.
Calls curl_global_init
, which is not thread-safe. For more information consult curl_global_init(3).
- Since
- 0.1.0
30 : _curl_buffer_error{}
32 curl_global_init(CURL_GLOBAL_ALL);
33 _connection = curl_easy_init();
◆ CURLWrapper() [2/3]
mastodonpp::CURLWrapper::CURLWrapper |
( |
const CURLWrapper & |
other | ) |
|
|
default |
◆ CURLWrapper() [3/3]
mastodonpp::CURLWrapper::CURLWrapper |
( |
CURLWrapper && |
other | ) |
|
|
defaultnoexcept |
◆ ~CURLWrapper()
mastodonpp::CURLWrapper::~CURLWrapper |
( |
| ) |
|
|
virtualnoexcept |
Cleans up curl and connection.
Calls curl_global_cleanup
, which is not thread-safe. For more information consult curl_global_cleanup(3).
- Since
- 0.1.0
38 curl_easy_cleanup(_connection);
39 curl_global_cleanup();
◆ make_request()
Make a request.
- Parameters
-
method | The HTTP method. |
uri | The full URI. |
- Since
- 0.1.0
45 debuglog <<
"Making request to: " << uri <<
'\n';
50 case http_method::GET:
53 code = curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
56 case http_method::POST:
59 code = curl_easy_setopt(_connection, CURLOPT_POST, 1L);
65 throw CURLException{code,
"Failed to set HTTP method",
70 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
73 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
77 code = curl_easy_perform(_connection);
82 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
83 answer.http_status = static_cast<uint16_t>(http_status);
84 debuglog <<
"HTTP status code: " << http_status <<
'\n';
86 answer.headers = _curl_buffer_headers;
87 answer.body = _curl_buffer_body;
91 answer.curl_error_code = static_cast<uint8_t>(code);
92 answer.error_message = _curl_buffer_error;
93 debuglog <<
"libcurl error: " << code <<
'\n';
94 debuglog << _curl_buffer_error <<
'\n';
◆ operator=() [1/2]
Copy assignment operator.
◆ operator=() [2/2]
Move assignment operator.
The documentation for this class was generated from the following files: