roar
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Roar::Curl::Request Class Reference

#include <request.hpp>

Collaboration diagram for Roar::Curl::Request:

Public Types

using LogsType = std::vector< VerboseLogEntry >
 

Public Member Functions

 Request ()
 
RequestbasicAuth (std::string const &name, std::string const &password)
 Sets a basic auth header.
 
RequestbearerAuth (std::string const &bearerToken)
 Sets a bearer auth header.
 
RequestacceptEncoding (std::string const &encoding)
 Sets the Accept-Encoding haeder.
 
RequestfollowRedirects (bool doFollow)
 Automatically follow redirects?
 
RequestmaxRedirects (std::size_t maxRedirects)
 Sets the maximum number of redirects to follow.
 
RequestautoReferer (bool doAutoRefer)
 When enabled libcurl will automatically set the Referer: header field in HTTP requests to the full URL where it follows a Location: redirect.
 
RequestsetHeaderFields (std::unordered_map< std::string, std::string > const &fields)
 Set the all header fields at one using the map.
 
RequestsetHeader (std::string const &key, std::string const &value)
 Set the speficied header field with value.
 
RequestsetHeader (boost::beast::http::field key, std::string const &value)
 Set the speficied header field with value.
 
RequestverifyPeer (bool verify=true)
 Verify the peer in secure requests?
 
RequestverifyHost (bool verify=true)
 Verify host in secure request?
 
Requestexpect100Continue ()
 expect 100 continue?
 
RequestconnectTimeout (std::chrono::milliseconds timeout)
 Set a timeout for connects.
 
RequesttransferTimeout (std::chrono::milliseconds timeout)
 Set a timeout for transfers.
 
RequestuseSignals (bool useSignal)
 Shall curl use signals?
 
Requestsink (std::function< void(char const *, std::size_t)> const &sinkFunction, std::function< void()> onComplete=[]() {})
 A sink that is a simple function accepting the data.
 
Requestsink (std::string &str)
 Installs a sink to a string.
 
Requestsink (std::ostream &stream)
 Installs a sink to a stream.
 
Requestsink (std::filesystem::path const &path)
 Installs a sink to a file.
 
Requestsink (Sink &customSink)
 Installs a custom sink.
 
RequestaddLibcurlDefaultSink ()
 Reenables outputting to stdout.
 
Requestproxy (std::string const &url)
 Enables the use of a proxy.
 
Requesttunnel (std::string const &url)
 Enables the use of a proxy tunnel (HTTPS proxy).
 
RequestunixSocket (std::filesystem::path const &path)
 Use unix socket instead of a tcp socket.
 
RequestcontentType (std::string const &type)
 Sets the Content-Type header.
 
Requestverbose (bool enable=true)
 Enables / Disables verbose logging.
 
Requestverbose (LogsType &logs)
 Will enable verbose logging and log to log container.
 
RequestonHeaderValue (std::function< void(std::string const &, std::string const &)> const &headerReceiver)
 The passed function is called when a header is received.
 
RequestheaderSink (std::unordered_map< std::string, std::string > &headers)
 Register a sink for header values, that takes all received headers.
 
template<typename SourceT , typename... Args>
RequestemplaceSource (Args &&... args)
 Inplace construct a source that is used for the sent body.
 
Requestsource (char const *str)
 Set the source from a c-string.
 
Requestmethod (std::string const &method)
 Set the request method.
 
Requestverb (std::string const &verb)
 Alias for method.
 
Requestsource (std::string str)
 Set the source from a string.
 
Requestsource (std::filesystem::path path)
 Set the source to be a file.
 
Response get (std::string const &url)
 Finishes and performs the request as a get request.
 
Response put (std::string const &url)
 Finishes and performs the request as a put request.
 
Response post (std::string const &url)
 Finishes and performs the request as a post request.
 
Response delete_ (std::string const &url)
 Finishes and performs the request as a delete request.
 
Response options (std::string const &url)
 Finishes and performs the request as a options request.
 
Response head (std::string const &url)
 Finishes and performs the request as a head request.
 
Response patch (std::string const &url)
 Finishes and performs the request as a patch request.
 
Response custom (std::string const &request, std::string const &url)
 For requests outside the common verbs. (Or for put requests without body).
 
Instanceinstance ()
 Returns the underlying curl instance.
 
Requesturl (std::string const &url)
 The the url of the request.
 
Response perform ()
 Perform the request. Use this like verb("GET").url("bla.com").perform(). There are get,patch,put etc which combine these into one.
 

Private Member Functions

void check (CURLcode code)
 
void setupSource (bool chunked)
 
void setupSinks ()
 

Private Attributes

Instance instance_
 
std::function< void(char *, std::size_t)> sink_
 
std::vector< std::pair< std::function< void(char *, std::size_t)>, std::function< void()> > > sinks_
 
std::unique_ptr< Sourcesource_
 
std::vector< std::function< void(std::string const &, std::string const &)> > headerReceivers_
 
std::unordered_map< std::string, std::string > headerFields_
 

Member Typedef Documentation

◆ LogsType

Constructor & Destructor Documentation

◆ Request()

Roar::Curl::Request::Request ( )

Member Function Documentation

◆ acceptEncoding()

Request & Roar::Curl::Request::acceptEncoding ( std::string const &  encoding)

Sets the Accept-Encoding haeder.

Parameters
encodingThe accepted encoding.
Returns
Request& Returned for chaining.

◆ addLibcurlDefaultSink()

Request & Roar::Curl::Request::addLibcurlDefaultSink ( )

Reenables outputting to stdout.

Returns
Request& Returned for chaining.

◆ autoReferer()

Request & Roar::Curl::Request::autoReferer ( bool  doAutoRefer)

When enabled libcurl will automatically set the Referer: header field in HTTP requests to the full URL where it follows a Location: redirect.

Parameters
doAutoRefer
Returns
Request& Returned for chaining.

◆ basicAuth()

Request & Roar::Curl::Request::basicAuth ( std::string const &  name,
std::string const &  password 
)

Sets a basic auth header.

Parameters
nameUser name
passwordUser password.
Returns
Request& Returned for chaining.

◆ bearerAuth()

Request & Roar::Curl::Request::bearerAuth ( std::string const &  bearerToken)

Sets a bearer auth header.

Parameters
bearerTokenThe token to send.
Returns
Request& Returned for chaining.

◆ check()

void Roar::Curl::Request::check ( CURLcode  code)
private

◆ connectTimeout()

Request & Roar::Curl::Request::connectTimeout ( std::chrono::milliseconds  timeout)

Set a timeout for connects.

Parameters
timeoutThe timeout in milliseconds.
Returns
Request& Returned for chaining.

◆ contentType()

Request & Roar::Curl::Request::contentType ( std::string const &  type)

Sets the Content-Type header.

Parameters
typeThe content type to set.
Returns
Request& Returned for chaining.

◆ custom()

Response Roar::Curl::Request::custom ( std::string const &  request,
std::string const &  url 
)

For requests outside the common verbs. (Or for put requests without body).

Parameters
requestA custom request verb
urlThe target to send this request to.
Returns
A response object.

◆ delete_()

Response Roar::Curl::Request::delete_ ( std::string const &  url)

Finishes and performs the request as a delete request.

Parameters
urlThe target to send this request to.
Returns
A response object.

◆ emplaceSource()

template<typename SourceT , typename... Args>
Request & Roar::Curl::Request::emplaceSource ( Args &&...  args)
inline

Inplace construct a source that is used for the sent body.

Template Parameters
SourceTThe source type (cannot be inferred).
ArgsForwarded args to the source constructor.
Parameters
argsThe forwarded args.
Returns
Request& Returned for chaining.

◆ expect100Continue()

Request & Roar::Curl::Request::expect100Continue ( )

expect 100 continue?

◆ followRedirects()

Request & Roar::Curl::Request::followRedirects ( bool  doFollow)

Automatically follow redirects?

Parameters
doFollowWill follow redirects if true.
Returns
Request& Returned for chaining.

◆ get()

Response Roar::Curl::Request::get ( std::string const &  url)

Finishes and performs the request as a get request.

Parameters
urlThe target to send this request to.
Returns
A response object.

◆ head()

Response Roar::Curl::Request::head ( std::string const &  url)

Finishes and performs the request as a head request.

Parameters
urlThe target to send this request to.
Returns
A response object.

◆ headerSink()

Request & Roar::Curl::Request::headerSink ( std::unordered_map< std::string, std::string > &  headers)

Register a sink for header values, that takes all received headers.

Parameters
headersA container that takes the header values. You must keep it alive.
Returns
Request& Returned for chaining.

◆ instance()

Instance & Roar::Curl::Request::instance ( )

Returns the underlying curl instance.

◆ maxRedirects()

Request & Roar::Curl::Request::maxRedirects ( std::size_t  maxRedirects)

Sets the maximum number of redirects to follow.

Parameters
maxRedirectsThe maximum number of redirects to follow.
Returns
Request& Returned for chaining.

◆ method()

Request & Roar::Curl::Request::method ( std::string const &  method)

Set the request method.

Parameters
methodThe method to set.
Returns
Request& Returned for chaining.

◆ onHeaderValue()

Request & Roar::Curl::Request::onHeaderValue ( std::function< void(std::string const &, std::string const &)> const &  headerReceiver)

The passed function is called when a header is received.

Parameters
headerReceiverA function taking header values.
Returns
Request& Returned for chaining.

◆ options()

Response Roar::Curl::Request::options ( std::string const &  url)

Finishes and performs the request as a options request.

Parameters
urlThe target to send this request to.
Returns
A response object.

◆ patch()

Response Roar::Curl::Request::patch ( std::string const &  url)

Finishes and performs the request as a patch request.

Parameters
urlThe target to send this request to.
Returns
A response object.

◆ perform()

Response Roar::Curl::Request::perform ( )

Perform the request. Use this like verb("GET").url("bla.com").perform(). There are get,patch,put etc which combine these into one.

◆ post()

Response Roar::Curl::Request::post ( std::string const &  url)

Finishes and performs the request as a post request.

Parameters
urlThe target to send this request to.
Returns
A response object.

◆ proxy()

Request & Roar::Curl::Request::proxy ( std::string const &  url)

Enables the use of a proxy.

Parameters
urlThe url to the proxy.
Returns
Request& Returned for chaining.

◆ put()

Response Roar::Curl::Request::put ( std::string const &  url)

Finishes and performs the request as a put request.

Parameters
urlThe target to send this request to.
Returns
A response object.

◆ setHeader() [1/2]

Request & Roar::Curl::Request::setHeader ( boost::beast::http::field  key,
std::string const &  value 
)

Set the speficied header field with value.

Parameters
keyThe field.
valueThe value.
Returns
Request& Returned for chaining.

◆ setHeader() [2/2]

Request & Roar::Curl::Request::setHeader ( std::string const &  key,
std::string const &  value 
)

Set the speficied header field with value.

Parameters
keyThe field.
valueThe value.
Returns
Request& Returned for chaining.

◆ setHeaderFields()

Request & Roar::Curl::Request::setHeaderFields ( std::unordered_map< std::string, std::string > const &  fields)

Set the all header fields at one using the map.

Parameters
fieldsA key/value object for header fields
Returns
Request& Returned for chaining.

◆ setupSinks()

void Roar::Curl::Request::setupSinks ( )
private

◆ setupSource()

void Roar::Curl::Request::setupSource ( bool  chunked)
private

◆ sink() [1/5]

Request & Roar::Curl::Request::sink ( Sink customSink)

Installs a custom sink.

Parameters
customSinkA sink deriving from Roar::Curl::Sink
Returns
Request& Returned for chaining.

◆ sink() [2/5]

Request & Roar::Curl::Request::sink ( std::filesystem::path const &  path)

Installs a sink to a file.

This function does not check whether the path is writeable to.

Parameters
pathThe path that should be written to.
Returns
Request& Returned for chaining.

◆ sink() [3/5]

Request & Roar::Curl::Request::sink ( std::function< void(char const *, std::size_t)> const &  sinkFunction,
std::function< void()>  onComplete = []() {} 
)
inline

A sink that is a simple function accepting the data.

Parameters
sinkFunctionThis function will be repeatedly called with new data.
Returns
Request& Returned for chaining

◆ sink() [4/5]

Request & Roar::Curl::Request::sink ( std::ostream &  stream)

Installs a sink to a stream.

Parameters
streamThe stream.
Returns
Request& Returned for chaining.

◆ sink() [5/5]

Request & Roar::Curl::Request::sink ( std::string &  str)

Installs a sink to a string.

Parameters
strThe string that should be written to.
Returns
Request& Returned for chaining.

◆ source() [1/3]

Request & Roar::Curl::Request::source ( char const *  str)

Set the source from a c-string.

Parameters
strA string source.
Returns
Request& Returned for chaining.

◆ source() [2/3]

Request & Roar::Curl::Request::source ( std::filesystem::path  path)

Set the source to be a file.

Parameters
strA file source
Returns
Request& Returned for chaining.

◆ source() [3/3]

Request & Roar::Curl::Request::source ( std::string  str)

Set the source from a string.

Parameters
strA string source.
Returns
Request& Returned for chaining.

◆ transferTimeout()

Request & Roar::Curl::Request::transferTimeout ( std::chrono::milliseconds  timeout)

Set a timeout for transfers.

Parameters
timeoutThe timeout in milliseconds.
Returns
Request& Returned for chaining.

◆ tunnel()

Request & Roar::Curl::Request::tunnel ( std::string const &  url)

Enables the use of a proxy tunnel (HTTPS proxy).

Parameters
urlThe url to the proxy.
Returns
Request& Returned for chaining.

◆ unixSocket()

Request & Roar::Curl::Request::unixSocket ( std::filesystem::path const &  path)

Use unix socket instead of a tcp socket.

Parameters
pathPath to the unix socket.
Returns
Request& Returned for chaining.

◆ url()

Request & Roar::Curl::Request::url ( std::string const &  url)

The the url of the request.

Parameters
url

◆ useSignals()

Request & Roar::Curl::Request::useSignals ( bool  useSignal)

Shall curl use signals?

Parameters
useSignaluse signals yes/no?
Returns
Request& Returned for chaining.

◆ verb()

Request & Roar::Curl::Request::verb ( std::string const &  verb)

Alias for method.

Parameters
verb

◆ verbose() [1/2]

Request & Roar::Curl::Request::verbose ( bool  enable = true)

Enables / Disables verbose logging.

Parameters
enableenable verbose logging yes/no
Returns
Request& Returned for chaining.

◆ verbose() [2/2]

Request & Roar::Curl::Request::verbose ( LogsType logs)

Will enable verbose logging and log to log container.

Parameters
logsThe log container to log to. You must keep it alive.
Returns
Request& Returned for chaining.

◆ verifyHost()

Request & Roar::Curl::Request::verifyHost ( bool  verify = true)

Verify host in secure request?

Parameters
verifyverify yes/no?
Returns
Request& Returned for chaining.

◆ verifyPeer()

Request & Roar::Curl::Request::verifyPeer ( bool  verify = true)

Verify the peer in secure requests?

Parameters
verifyverify yes/no?
Returns
Request& Returned for chaining.

Member Data Documentation

◆ headerFields_

std::unordered_map<std::string, std::string> Roar::Curl::Request::headerFields_
private

◆ headerReceivers_

std::vector<std::function<void(std::string const&, std::string const&)> > Roar::Curl::Request::headerReceivers_
private

◆ instance_

Instance Roar::Curl::Request::instance_
private

◆ sink_

std::function<void(char*, std::size_t)> Roar::Curl::Request::sink_
private

◆ sinks_

std::vector<std::pair<std::function<void(char*, std::size_t)>, std::function<void()> > > Roar::Curl::Request::sinks_
private

◆ source_

std::unique_ptr<Source> Roar::Curl::Request::source_
private

The documentation for this class was generated from the following files: