10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
LibcurlHTTPCall.h
1#ifndef TENDUKE_HTTP_LIBCURLHTTPCALL_H
2#define TENDUKE_HTTP_LIBCURLHTTPCALL_H
3
4#include "http/HTTPCall.h"
5#include "http/HTTPRequest.h"
6#include "http/HTTPResponse.h"
7#include "net/URLs.h"
8
9#include <curl/curl.h>
10
11#include <cstddef>
12#include <map>
13#include <string>
14
15namespace tenduke { namespace http { namespace curl {
16
17
28 const char *line,
29 std::size_t len,
30 std::multimap<std::string, std::string> &headers
31);
32
33
38{
39public:
49 std::shared_ptr<const tenduke::http::HTTPRequest> request,
50 std::string userAgent,
51 const ::tenduke::net::URLs &urls,
52 bool verbose = false,
54 );
55 ~LibCurlHTTPCall() override;
56
57// tenduke::http::HTTPCall interface
58public:
59 std::unique_ptr<tenduke::http::HTTPResponse> execute() override;
60
61protected:
65 virtual void setRequestBody();
66
71 virtual void setRequestHeaders();
72
76 virtual void setRequestMethod();
77
82 virtual void restrictProtocols();
83
89 virtual void configureTLS();
90
94 virtual void setUrl();
95
97 const std::shared_ptr<const tenduke::http::HTTPRequest> request;
98
100 const std::unique_ptr<CURL, decltype(curl_easy_cleanup) *> curlHandle;
101
103 struct curl_slist *curlHeaders;
104 //char curlErrorMessage[CURL_ERROR_SIZE];
105
107 const std::string userAgent;
108
111
113 const std::size_t maxResponseBodySize;
114private:
115 const ::tenduke::net::URLs &urls;
116};
117
118
119}}}
120
121#endif // TENDUKE_HTTP_LIBCURLHTTPCALL_H
HTTP-call which executes the request and returns HTTPResponse.
Definition HTTPCall.h:15
virtual void configureTLS()
Enables TLS certificate verification of the CURL-call: the certificate chain and the host name are ve...
Definition LibcurlHTTPCall.cpp:337
virtual void restrictProtocols()
Restricts the CURL-call to protocols http and https, without following redirects.
Definition LibcurlHTTPCall.cpp:312
virtual void setRequestMethod()
Sets request method to the CURL-call.
Definition LibcurlHTTPCall.cpp:372
virtual void setRequestBody()
Sets request body to the CURL-call.
Definition LibcurlHTTPCall.cpp:381
const std::unique_ptr< CURL, decltype(curl_easy_cleanup) * > curlHandle
libcurl-handle for the request.
Definition LibcurlHTTPCall.h:100
bool verbose
If true, configure libcurl to provide verbose output.
Definition LibcurlHTTPCall.h:110
virtual void setUrl()
Sets URL to the CURL-call.
Definition LibcurlHTTPCall.cpp:362
const std::shared_ptr< const tenduke::http::HTTPRequest > request
The request.
Definition LibcurlHTTPCall.h:97
virtual void setRequestHeaders()
Sets request headers to the CURL-call.
Definition LibcurlHTTPCall.cpp:392
struct curl_slist * curlHeaders
libcurl header-list.
Definition LibcurlHTTPCall.h:103
std::unique_ptr< tenduke::http::HTTPResponse > execute() override
Executes the call synchronously.
Definition LibcurlHTTPCall.cpp:207
const std::size_t maxResponseBodySize
Maximum size of the response body in bytes.
Definition LibcurlHTTPCall.h:113
LibCurlHTTPCall(std::shared_ptr< const tenduke::http::HTTPRequest > request, std::string userAgent, const ::tenduke::net::URLs &urls, bool verbose=false, std::size_t maxResponseBodySize=DEFAULT_MAX_RESPONSE_BODY_SIZE)
Constructs new instance.
Definition LibcurlHTTPCall.cpp:125
const std::string userAgent
Useragent-string to use.
Definition LibcurlHTTPCall.h:107
Implementation of HTTP-client using libcurl.
Definition LibcurlHTTPCall.h:15
void parseResponseHeaderLine(const char *line, std::size_t len, std::multimap< std::string, std::string > &headers)
Parses one response header line received from libcurl and adds the header to headers.
Definition LibcurlHTTPCall.cpp:74
HTTP-related services.
Definition BadRequest.h:6
const std::size_t DEFAULT_MAX_RESPONSE_BODY_SIZE
Default maximum size of a response body in bytes (10 MiB).
Definition HTTPRequest.h:21
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4