8#include <boost/beast/http/field.hpp>
10#ifdef ROAR_ENABLE_NLOHMANN_JSON
11# include <nlohmann/json.hpp>
21#include <unordered_map>
116 Request&
setHeader(boost::beast::http::field key, std::string
const& value);
170 std::function<
void(
char const*, std::size_t)>
const& sinkFunction,
171 std::function<
void()> onComplete = []() {})
174 std::pair<std::function<
void(
char*, std::size_t)>, std::function<
void()>>(sinkFunction, onComplete));
178#ifdef ROAR_ENABLE_NLOHMANN_JSON
276 Request&
onHeaderValue(std::function<
void(std::string
const&, std::string
const&)>
const& headerReceiver);
294 template <
typename SourceT,
typename... Args>
297 source_ = std::make_unique<SourceT>(std::forward<Args>(args)...);
425 void check(CURLcode code);
431 std::function<void(
char*, std::size_t)>
sink_;
432 std::vector<std::pair<std::function<void(
char*, std::size_t)>, std::function<void()>>>
sinks_;
Definition instance.hpp:11
Definition request.hpp:36
Request & verbose(bool enable=true)
Enables / Disables verbose logging.
Definition request.cpp:151
void check(CURLcode code)
Definition request.cpp:354
Request & unixSocket(std::filesystem::path const &path)
Use unix socket instead of a tcp socket.
Definition request.cpp:339
std::vector< VerboseLogEntry > LogsType
Definition request.hpp:38
Response custom(std::string const &request, std::string const &url)
For requests outside the common verbs. (Or for put requests without body).
Definition request.cpp:145
Request & proxy(std::string const &url)
Enables the use of a proxy.
Definition request.cpp:328
Response perform()
Perform the request. Use this like verb("GET").url("bla.com").perform(). There are get,...
Definition request.cpp:360
Request & verb(std::string const &verb)
Alias for method.
Definition request.cpp:240
Request & setHeader(std::string const &key, std::string const &value)
Set the speficied header field with value.
Definition request.cpp:101
Request & method(std::string const &method)
Set the request method.
Definition request.cpp:344
Request & useSignals(bool useSignal)
Shall curl use signals?
Definition request.cpp:172
Request()
Definition request.cpp:66
Request & basicAuth(std::string const &name, std::string const &password)
Sets a basic auth header.
Definition request.cpp:70
Request & contentType(std::string const &type)
Sets the Content-Type header.
Definition request.cpp:111
Request & connectTimeout(std::chrono::milliseconds timeout)
Set a timeout for connects.
Definition request.cpp:162
Request & expect100Continue()
expect 100 continue?
Definition request.cpp:78
Request & onHeaderValue(std::function< void(std::string const &, std::string const &)> const &headerReceiver)
The passed function is called when a header is received.
Definition request.cpp:177
Request & verifyPeer(bool verify=true)
Verify the peer in secure requests?
Definition request.cpp:115
void setupSource(bool chunked)
Definition request.cpp:314
std::vector< std::pair< std::function< void(char *, std::size_t)>, std::function< void()> > > sinks_
Definition request.hpp:432
Request & followRedirects(bool doFollow)
Automatically follow redirects?
Definition request.cpp:125
Request & transferTimeout(std::chrono::milliseconds timeout)
Set a timeout for transfers.
Definition request.cpp:167
std::vector< std::function< void(std::string const &, std::string const &)> > headerReceivers_
Definition request.hpp:434
Response post(std::string const &url)
Finishes and performs the request as a post request.
Definition request.cpp:198
Request & maxRedirects(std::size_t maxRedirects)
Sets the maximum number of redirects to follow.
Definition request.cpp:130
Request & acceptEncoding(std::string const &encoding)
Sets the Accept-Encoding haeder.
Definition request.cpp:90
void setupSinks()
Definition request.cpp:323
Request & tunnel(std::string const &url)
Enables the use of a proxy tunnel (HTTPS proxy).
Definition request.cpp:333
std::unordered_map< std::string, std::string > headerFields_
Definition request.hpp:435
Instance instance_
Definition request.hpp:430
Request & setHeaderFields(std::unordered_map< std::string, std::string > const &fields)
Set the all header fields at one using the map.
Definition request.cpp:95
Response head(std::string const &url)
Finishes and performs the request as a head request.
Definition request.cpp:228
Request & autoReferer(bool doAutoRefer)
When enabled libcurl will automatically set the Referer: header field in HTTP requests to the full UR...
Definition request.cpp:135
Response patch(std::string const &url)
Finishes and performs the request as a patch request.
Definition request.cpp:234
Response delete_(std::string const &url)
Finishes and performs the request as a delete request.
Definition request.cpp:216
Request & source(char const *str)
Set the source from a c-string.
Definition request.cpp:298
Request & url(std::string const &url)
The the url of the request.
Definition request.cpp:245
std::unique_ptr< Source > source_
Definition request.hpp:433
Request & bearerAuth(std::string const &bearerToken)
Sets a bearer auth header.
Definition request.cpp:83
Response put(std::string const &url)
Finishes and performs the request as a put request.
Definition request.cpp:190
Request & sink(std::function< void(char const *, std::size_t)> const &sinkFunction, std::function< void()> onComplete=[]() {})
A sink that is a simple function accepting the data.
Definition request.hpp:169
Response get(std::string const &url)
Finishes and performs the request as a get request.
Definition request.cpp:140
Request & emplaceSource(Args &&... args)
Inplace construct a source that is used for the sent body.
Definition request.hpp:295
Request & headerSink(std::unordered_map< std::string, std::string > &headers)
Register a sink for header values, that takes all received headers.
Definition request.cpp:184
Request & verifyHost(bool verify=true)
Verify host in secure request?
Definition request.cpp:120
Request & addLibcurlDefaultSink()
Reenables outputting to stdout.
Definition request.cpp:292
Instance & instance()
Returns the underlying curl instance.
Definition request.cpp:349
std::function< void(char *, std::size_t)> sink_
Definition request.hpp:431
Response options(std::string const &url)
Finishes and performs the request as a options request.
Definition request.cpp:222
This class is returned by a Request class when the request is performed.
Definition response.hpp:16
This class extends the boost::beast::http::request<BodyT> with additional convenience.
Definition request.hpp:52
Definition curl_error.hpp:9
std::ostream & operator<<(std::ostream &stream, Request::LogsType const &logs)
Definition request.cpp:379
Definition request.hpp:30
curl_infotype type
Definition request.hpp:31
std::string data
Definition request.hpp:32