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.
The first time an instance of CURLWrapper is created, it calls curl_global_init
, which is not thread-safe. For more information consult curl_global_init(3).
- Since
- 0.1.0
36 : _curl_buffer_error{}
38 if (curlwrapper_instances == 0)
40 curl_global_init(CURL_GLOBAL_ALL);
42 ++curlwrapper_instances;
43 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (+1)\n";
45 _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
50 curl_easy_cleanup(_connection);
52 --curlwrapper_instances;
53 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (-1)\n";
54 if (curlwrapper_instances == 0)
56 curl_global_cleanup();
◆ get_curl_easy_handle()
CURL* mastodonpp::CURLWrapper::get_curl_easy_handle |
( |
| ) |
|
|
inline |
Returns pointer to the CURL easy handle.
You can use this handle to set or modify curl options. For more information consult curl_easy_setopt(3).
- Since
- 0.1.0
◆ make_request()
Make a request.
- Parameters
-
method | The HTTP method. |
uri | The full URI. |
- Since
- 0.1.0
63 debuglog <<
"Making request to: " << uri <<
'\n';
68 case http_method::GET:
71 code = curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
74 case http_method::POST:
77 code = curl_easy_setopt(_connection, CURLOPT_POST, 1L);
80 case http_method::PATCH:
83 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
86 case http_method::PUT:
89 code = curl_easy_setopt(_connection, CURLOPT_UPLOAD, 1L);
92 case http_method::DELETE:
95 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
101 throw CURLException{code,
"Failed to set HTTP method",
106 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
107 if (code != CURLE_OK)
109 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
113 code = curl_easy_perform(_connection);
114 if (code == CURLE_OK)
118 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
119 answer.http_status = static_cast<uint16_t>(http_status);
120 debuglog <<
"HTTP status code: " << http_status <<
'\n';
122 answer.headers = _curl_buffer_headers;
123 answer.body = _curl_buffer_body;
127 answer.curl_error_code = static_cast<uint8_t>(code);
128 answer.error_message = _curl_buffer_error;
129 debuglog <<
"libcurl error: " << code <<
'\n';
130 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: