http class. Do not use this directly.
More...
#include <mastodon-cpp.hpp>
http class. Do not use this directly.
- Since
- before 0.11.0
◆ http()
API::http::http |
( |
const API & |
api, |
|
|
const string & |
instance, |
|
|
const string & |
access_token |
|
) |
| |
|
explicit |
Constructs new http object.
- Parameters
-
API | Parent object. |
instance | Instance domain name |
access_token | Access token |
- Since
- before 0.11.0
53 , _access_token(access_token)
54 , _cancel_stream(
false)
56 Poco::Net::initializeSSL();
60 string env_proxy = Environment::get(
"http_proxy");
64 if ((pos = env_proxy.find(
"//")) != string::npos)
66 env_proxy = env_proxy.substr(pos + 2);
68 if ((pos = env_proxy.find(
'/')) != string::npos)
70 env_proxy = env_proxy.substr(0, pos);
73 if ((pos = env_proxy.find(
'@')) != string::npos)
75 string hostport = env_proxy.substr(pos + 1);
76 string userpw = env_proxy.substr(0, pos);
84 catch (
const std::exception &)
void set_proxy(const string &hostport, const string &userpw="")
Set proxy. Do not call this directly.
Definition: http.cpp:96
◆ cancel_stream()
void API::http::cancel_stream |
( |
| ) |
|
Cancels the stream. Use only with streams.
Cancels the stream next time data comes in. Can take a
few seconds. This works only with streams, because only
streams have an own http object.
- Since
- 0.12.2
354 _cancel_stream =
true;
355 _streamthread.join();
◆ get_mutex()
std::mutex & API::http::get_mutex |
( |
| ) |
|
Gets the mutex guarding the string that is written to.
The mutex guards the function that writes to the string
you specified in get_stream().
- Returns
- A reference of the mutex.
- Since
- 0.12.3
◆ request()
HTTP Request.
- Parameters
-
meth | A method defined in http::method. |
path | The API call as string. |
formdata | The form data for PATCH and POST requests. |
- Since
- 0.100.0
147 return request_common(meth, path, formdata, answer);
◆ request_stream()
void API::http::request_stream |
( |
const string & |
path, |
|
|
string & |
stream |
|
) |
| |
HTTP Request for streams.
- Parameters
-
path | The API call as string. |
stream | The stream of data that is returned. |
- Since
- 0.100.0
153 _streamthread = std::thread(
157 ret = request_common(http_method::GET_STREAM, path,
159 ttdebug <<
"Remaining content of the stream: " << stream <<
'\n';
163 stream +=
"event: ERROR\ndata: {\"error_code\":" 164 + std::to_string(ret.
error_code) +
",\"http_error\":" Return type for API calls.
Definition: return_types.hpp:93
uint8_t error_code
Error code.
Definition: return_types.hpp:42
uint16_t http_error_code
HTTP error code.
Definition: return_types.hpp:56
◆ set_proxy()
void API::http::set_proxy |
( |
const string & |
hostport, |
|
|
const string & |
userpw = "" |
|
) |
| |
Set proxy. Do not call this directly.
- Parameters
-
hostport | host[:port] |
userpw | user[:password] (optional) |
- Since
- 0.110.0
100 HTTPSClientSession::ProxyConfig proxyconfig;
101 size_t pos = hostport.find(
':');
103 proxyconfig.host = hostport.substr(0, pos);
104 if (pos != string::npos)
106 proxyconfig.port = std::stoi(hostport.substr(pos + 1));
113 pos = userpw.find(
':');
114 Poco::URI::decode(userpw.substr(0, pos), username);
115 proxyconfig.username = username;
117 if (pos != string::npos)
120 Poco::URI::decode(userpw.substr(pos + 1), password);
121 proxyconfig.password = password;
125 HTTPSClientSession::setGlobalProxyConfig(proxyconfig);
126 ttdebug <<
"Set proxy to " << hostport <<
".\n";
128 catch (
const std::exception &e)
132 std::rethrow_exception(std::current_exception());
bool exceptions(const bool &value)
Turn exceptions on or off. Defaults to off.
Definition: mastodon-cpp.cpp:283
The documentation for this class was generated from the following files: