10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
HTTPRequest.h
1#ifndef TENDUKE_HTTP_HTTPREQUEST_H
2#define TENDUKE_HTTP_HTTPREQUEST_H
3
4#include "./HTTPRequestAuthenticator.h"
5#include "../net/URL.h"
6
7#include <cstddef>
8#include <map>
9#include <memory>
10#include <string>
11
12namespace tenduke { namespace http {
13
15const long DEFAULT_CONNECTION_TIMEOUT_MS = 30L * 1000L;
16
18const long DEFAULT_TIMEOUT_MS = 60L * 1000L;
19
21const std::size_t DEFAULT_MAX_RESPONSE_BODY_SIZE = 10 * 1024 * 1024;
22
27{
28public:
40 std::string method,
42 const std::multimap<std::string, std::string> &headers = std::multimap<std::string, std::string>(),
43 std::shared_ptr<const tenduke::http::HTTPRequestAuthenticator> requestAuthenticator = nullptr,
44 std::string messageBody = "",
45 long connectionTimeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS,
46 long timeoutMs = DEFAULT_TIMEOUT_MS
47 ) : method(std::move(method)), messageBody(std::move(messageBody)), url(std::move(url)),
48 headers(headers), requestAuthenticator(std::move(requestAuthenticator)),
49 connectionTimeoutMs(connectionTimeoutMs), timeoutMs(timeoutMs)
50 {}
51
56 const std::string & getMessageBody() const {return messageBody;}
57
62 const std::string & getMethod() const {return method;}
63
68 const ::tenduke::net::URL getURL() const {return url;}
69
74 const std::multimap<std::string, std::string> & getHeaders() const {return headers;}
75
80 const std::shared_ptr<const tenduke::http::HTTPRequestAuthenticator> & getRequestAuthenticator() const {return requestAuthenticator;}
81
86 long getConnectionTimeoutMs() const {return connectionTimeoutMs;}
87
92 long getTimeoutMs() const {return timeoutMs;}
93
98 bool hasBody() const {return !messageBody.empty();}
99
100private:
101 const std::string method;
102 const std::string messageBody;
103 const ::tenduke::net::URL url;
104 const std::multimap<std::string, std::string> headers;
105 const std::shared_ptr<const tenduke::http::HTTPRequestAuthenticator> requestAuthenticator;
106 const long connectionTimeoutMs;
107 const long timeoutMs;
108};
109
110
111}}
112
113#endif // TENDUKE_HTTP_HTTPREQUEST_H
HTTPRequest(std::string method, ::tenduke::net::URL url, const std::multimap< std::string, std::string > &headers=std::multimap< std::string, std::string >(), std::shared_ptr< const tenduke::http::HTTPRequestAuthenticator > requestAuthenticator=nullptr, std::string messageBody="", long connectionTimeoutMs=DEFAULT_CONNECTION_TIMEOUT_MS, long timeoutMs=DEFAULT_TIMEOUT_MS)
Constructs new instance.
Definition HTTPRequest.h:39
long getTimeoutMs() const
Returns total time out in ms, 0 if the request does not time out.
Definition HTTPRequest.h:92
const std::shared_ptr< const tenduke::http::HTTPRequestAuthenticator > & getRequestAuthenticator() const
Returns HTTP request authenticator.
Definition HTTPRequest.h:80
HTTPRequest(std::string method, ::tenduke::net::URL url, const std::multimap< std::string, std::string > &headers=std::multimap< std::string, std::string >(), std::shared_ptr< const tenduke::http::HTTPRequestAuthenticator > requestAuthenticator=nullptr, std::string messageBody="", long connectionTimeoutMs=DEFAULT_CONNECTION_TIMEOUT_MS, long timeoutMs=DEFAULT_TIMEOUT_MS)
Constructs new instance.
Definition HTTPRequest.h:39
const std::string & getMethod() const
Returns the method.
Definition HTTPRequest.h:62
const ::tenduke::net::URL getURL() const
Returns the URL.
Definition HTTPRequest.h:68
bool hasBody() const
Checks if request has body.
Definition HTTPRequest.h:98
const std::multimap< std::string, std::string > & getHeaders() const
Returns request headers.
Definition HTTPRequest.h:74
const std::string & getMessageBody() const
Returns the message body.
Definition HTTPRequest.h:56
long getConnectionTimeoutMs() const
Returns connection timeout in ms.
Definition HTTPRequest.h:86
Represents URL.
Definition URL.h:23
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
const long DEFAULT_CONNECTION_TIMEOUT_MS
Default connection time out in milliseconds.
Definition HTTPRequest.h:15
const long DEFAULT_TIMEOUT_MS
Default total time out in milliseconds.
Definition HTTPRequest.h:18
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4