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
32 : _curl_buffer_error{}
34 if (curlwrapper_instances == 0)
36 curl_global_init(CURL_GLOBAL_ALL);
38 ++curlwrapper_instances;
39 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (+1)\n";
41 _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
46 curl_easy_cleanup(_connection);
48 --curlwrapper_instances;
49 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (-1)\n";
50 if (curlwrapper_instances == 0)
52 curl_global_cleanup();
◆ make_request()
Make a request.
- Parameters
-
method | The HTTP method. |
uri | The full URI. |
- Since
- 0.1.0
59 debuglog <<
"Making request to: " << uri <<
'\n';
64 case http_method::GET:
67 code = curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
70 case http_method::POST:
73 code = curl_easy_setopt(_connection, CURLOPT_POST, 1L);
76 case http_method::PATCH:
79 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
82 case http_method::PUT:
85 code = curl_easy_setopt(_connection, CURLOPT_UPLOAD, 1L);
88 case http_method::DELETE:
91 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
97 throw CURLException{code,
"Failed to set HTTP method",
102 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
103 if (code != CURLE_OK)
105 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
109 code = curl_easy_perform(_connection);
110 if (code == CURLE_OK)
114 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
115 answer.http_status = static_cast<uint16_t>(http_status);
116 debuglog <<
"HTTP status code: " << http_status <<
'\n';
118 answer.headers = _curl_buffer_headers;
119 answer.body = _curl_buffer_body;
123 answer.curl_error_code = static_cast<uint8_t>(code);
124 answer.error_message = _curl_buffer_error;
125 debuglog <<
"libcurl error: " << code <<
'\n';
126 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: