libnick 2024.9.2
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
curleasy.h
Go to the documentation of this file.
1
23#ifndef CURLEASY_H
24#define CURLEASY_H
25
26#include <functional>
27#include <ostream>
28#include <string>
29#include <vector>
30#include <curl/curl.h>
31
33{
34 using CurlProgressFunction = std::function<int(curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)>;
35
40 {
41 public:
47 CurlEasy(const std::string& url = "");
56 const std::string& getUrl() const;
61 void setUrl(const std::string& url);
66 bool getNoBody() const;
71 void setNoBody(bool noBody);
76 const std::vector<std::string>& getHeaders() const;
82 bool setHeaders(const std::vector<std::string>& headers);
87 const std::string& getUserAgent() const;
92 void setUserAgent(const std::string& userAgent);
97 std::basic_ostream<char>* getStream() const;
102 void setStream(std::basic_ostream<char>* stream);
118 bool reset(const std::string& url = "");
123 CURLcode perform();
124
125 private:
130 bool init();
131 CURL* m_curl;
132 struct curl_slist* m_headersList;
133 std::string m_url;
134 bool m_noBody;
135 std::vector<std::string> m_headers;
136 std::string m_userAgent;
137 std::basic_ostream<char>* m_stream;
138 CurlProgressFunction m_progress;
139 };
140}
141
142#endif //CURLEASY_H
An object for making easy curl requests.
Definition curleasy.h:40
CURLcode perform()
Performs the curl request.
const std::vector< std::string > & getHeaders() const
Gets the headers to include in the request.
const std::string & getUrl() const
Gets the url to make requests to.
const std::string & getUserAgent() const
Gets the user agent to use in the request.
void setNoBody(bool noBody)
Sets whether or not to include the body in the response.
void setUserAgent(const std::string &userAgent)
Sets the user agent to use in the request.
std::basic_ostream< char > * getStream() const
Gets the stream to write the response to.
CurlEasy(const std::string &url="")
Constructs a CurlEasy.
void setUrl(const std::string &url)
Sets the url to make requests to.
bool getNoBody() const
Gets whether or not to include the body in the response.
bool reset(const std::string &url="")
Resets the curl request.
void setProgressFunction(const CurlProgressFunction &progress)
Sets the progress function to use during the request.
const CurlProgressFunction & getProgressFunction() const
Gets the progress function to use during the request.
bool setHeaders(const std::vector< std::string > &headers)
Sets the headers to include in the request.
~CurlEasy()
Destructs a CurlEasy.
void setStream(std::basic_ostream< char > *stream)
Sets the stream to write the response to.
Definition curleasy.h:33
std::function< int(curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)> CurlProgressFunction
Definition curleasy.h:34