GPUdb C++ API  Version 7.1.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Http.hpp
Go to the documentation of this file.
1 #ifndef __GPUDB__HTTP_HPP__
2 #define __GPUDB__HTTP_HPP__
3 
4 #ifndef GPUDB_NO_HTTPS
5 #include <boost/asio/ssl.hpp>
6 #endif
7 
8 #include <stdint.h>
9 #include <map>
10 #include <string>
11 #include <vector>
12 
13 namespace gpudb {
14  class HttpUrl
15  {
16  public:
17  static const std::string HTTP;
18  static const std::string HTTPS;
19 
20  HttpUrl();
21  HttpUrl(const char* url);
22  HttpUrl(const std::string& url);
23  HttpUrl(const std::string& protocol,
24  const std::string& host,
25  uint16_t port,
26  const std::string& path,
27  const std::string& query = std::string());
28  HttpUrl(const HttpUrl& baseUrl,
29  const std::string& path,
30  const std::string& query = std::string());
31 
32  const std::string& getUrl() const;
33  const std::string& getProtocol() const;
34  bool isSecure() const;
35  const std::string& getHost() const;
36  uint16_t getPort() const;
37  const std::string& getPath() const;
38  const std::string& getQuery() const;
39 
44  std::string getAppendedUrl( const std::string& endpoint ) const;
45 
46  operator std::string() const;
47 
48  friend bool operator ==(const HttpUrl &lhs, const HttpUrl &rhs);
49  friend bool operator !=(const HttpUrl &lhs, const HttpUrl &rhs);
50 
51  private:
52  std::string m_url;
53  bool m_secure;
54  std::string m_host;
55  uint16_t m_port;
56  std::string m_path;
57  std::string m_query;
58 
59  void init(const std::string& url);
60  void createUrl();
61  };
62 
63  std::ostream& operator <<(std::ostream &stream, const HttpUrl &value);
64 
65 
66 
67  template<typename T>
69 
70  class HttpResponse;
71 
73  {
74  public:
75  static const std::string GET;
76  static const std::string HEAD;
77  static const std::string POST;
78 
79  HttpRequest();
80  HttpRequest(const HttpUrl& url);
81 
82  #ifndef GPUDB_NO_HTTPS
83  boost::asio::ssl::context* getSslContext();
84  #endif
85 
86  const HttpUrl& getUrl() const;
87  const std::string& getRequestMethod() const;
88  const std::string& getRequestHeader(const std::string& key) const;
89  std::map<std::string, std::string>& getRequestHeaders();
90  size_t getTimeout() const;
91 
92  #ifndef GPUDB_NO_HTTPS
93  void setSslContext(boost::asio::ssl::context* sslContext);
94  void setBypassSslCertCheck(const bool value);
95  #endif
96 
97  void setUrl(const HttpUrl& url);
98  void setRequestMethod(const std::string& method);
99  void addRequestHeader(const std::string& key, const std::string& value);
100  void setTimeout(const size_t timeout);
101 
102  void send(HttpResponse& response);
103 
104  protected:
105  virtual void read(const void*& data, size_t& length) const;
106 
107  private:
108  template<typename T>
109  friend class HttpConnection;
110 
111  #ifndef GPUDB_NO_HTTPS
112  boost::asio::ssl::context* m_sslContext;
113  bool m_bypassSslCertCheck;
114  #endif
115 
116  HttpUrl m_url;
117  std::string m_requestMethod;
118  std::map<std::string, std::string> m_requestHeaders;
119  size_t m_timeout;
120  };
121 
123  {
124  public:
126  BinaryHttpRequest(const HttpUrl& url);
127 
128  const std::vector<uint8_t>* getRequestBody();
129 
130  void setRequestBody(const std::vector<uint8_t>* requestBody);
131 
132  protected:
133  virtual void read(const void*& data, size_t& length) const;
134 
135  private:
136  const std::vector<uint8_t>* m_requestBody;
137  };
138 
140  {
141  public:
143  StringHttpRequest(const HttpUrl& url);
144 
145  const std::string* getRequestBody();
146 
147  void setRequestBody(const std::string* requestBody);
148 
149  protected:
150  virtual void read(const void*& data, size_t& length) const;
151 
152  private:
153  const std::string* m_requestBody;
154  };
155 
157  {
158  public:
159  HttpResponse();
160  virtual ~HttpResponse();
161 
162  const std::string& getResponseVersion() const;
163  unsigned int getResponseCode() const;
164  const std::string& getResponseMessage() const;
165  const std::string& getResponseHeader(const std::string& key) const;
166  const std::map<std::string, std::string>& getResponseHeaders() const;
167 
168  protected:
169  virtual void write(const void* data, const size_t length);
170 
171  private:
172  template<typename T>
173  friend class HttpConnection;
174 
175  std::string m_responseVersion;
176  unsigned int m_responseCode;
177  std::string m_responseMessage;
178  std::map<std::string, std::string> m_responseHeaders;
179  };
180 
182  {
183  public:
184  const std::vector<uint8_t>& getResponseBody() const;
185 
186  protected:
187  virtual void write(const void* data, const size_t length);
188 
189  private:
190  std::vector<uint8_t> m_responseBody;
191  };
192 
194  {
195  public:
196  const std::string& getResponseBody() const;
197 
198  protected:
199  virtual void write(const void* data, const size_t length);
200 
201  private:
202  std::string m_responseBody;
203  };
204 }
205 
206 #endif
const std::string & getPath() const
const std::map< std::string, std::string > & getResponseHeaders() const
const std::vector< uint8_t > * getRequestBody()
const std::string & getProtocol() const
virtual void write(const void *data, const size_t length)
bool isSecure() const
friend bool operator==(const HttpUrl &lhs, const HttpUrl &rhs)
std::map< std::string, std::string > & getRequestHeaders()
void setRequestBody(const std::string *requestBody)
const std::string & getResponseHeader(const std::string &key) const
const std::string & getResponseMessage() const
boost::asio::ssl::context * getSslContext()
virtual void read(const void *&data, size_t &length) const
virtual void read(const void *&data, size_t &length) const
void setRequestMethod(const std::string &method)
std::string getAppendedUrl(const std::string &endpoint) const
Returns a string with the passed in endpoint appended to this URL.
static const std::string POST
Definition: Http.hpp:77
void setBypassSslCertCheck(const bool value)
unsigned int getResponseCode() const
virtual void write(const void *data, const size_t length)
const std::string & getUrl() const
const std::vector< uint8_t > & getResponseBody() const
void setRequestBody(const std::vector< uint8_t > *requestBody)
const std::string & getRequestMethod() const
std::ostream & operator<<(std::ostream &stream, const HttpUrl &value)
void setTimeout(const size_t timeout)
void send(HttpResponse &response)
void setUrl(const HttpUrl &url)
friend bool operator!=(const HttpUrl &lhs, const HttpUrl &rhs)
static const std::string HTTPS
Definition: Http.hpp:18
static const std::string GET
Definition: Http.hpp:75
size_t getTimeout() const
const std::string & getResponseBody() const
static const std::string HTTP
Definition: Http.hpp:17
const std::string * getRequestBody()
virtual void write(const void *data, const size_t length)
void setSslContext(boost::asio::ssl::context *sslContext)
void addRequestHeader(const std::string &key, const std::string &value)
const std::string & getHost() const
const std::string & getQuery() const
const std::string & getRequestHeader(const std::string &key) const
uint16_t getPort() const
const std::string & getResponseVersion() const
static const std::string HEAD
Definition: Http.hpp:76
const HttpUrl & getUrl() const
virtual void read(const void *&data, size_t &length) const
virtual ~HttpResponse()