GPUdb C++ API  Version 6.1.0.0
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 
40  operator std::string() const;
41 
42  private:
43  std::string m_url;
44  bool m_secure;
45  std::string m_host;
46  uint16_t m_port;
47  std::string m_path;
48  std::string m_query;
49 
50  void init(const std::string& url);
51  void createUrl();
52  };
53 
54  std::ostream& operator <<(std::ostream& stream, const HttpUrl& value);
55 
56  template<typename T>
58 
59  class HttpResponse;
60 
62  {
63  public:
64  static const std::string GET;
65  static const std::string HEAD;
66  static const std::string POST;
67 
68  HttpRequest();
69  HttpRequest(const HttpUrl& url);
70 
71  #ifndef GPUDB_NO_HTTPS
72  boost::asio::ssl::context* getSslContext();
73  #endif
74 
75  const HttpUrl& getUrl() const;
76  const std::string& getRequestMethod() const;
77  const std::string& getRequestHeader(const std::string& key) const;
78  std::map<std::string, std::string>& getRequestHeaders();
79  size_t getTimeout() const;
80 
81  #ifndef GPUDB_NO_HTTPS
82  void setSslContext(boost::asio::ssl::context* sslContext);
83  #endif
84 
85  void setUrl(const HttpUrl& url);
86  void setRequestMethod(const std::string& method);
87  void addRequestHeader(const std::string& key, const std::string& value);
88  void setTimeout(const size_t timeout);
89 
90  void send(HttpResponse& response);
91 
92  protected:
93  virtual void read(const void*& data, size_t& length) const;
94 
95  private:
96  template<typename T>
97  friend class HttpConnection;
98 
99  #ifndef GPUDB_NO_HTTPS
100  boost::asio::ssl::context* m_sslContext;
101  #endif
102 
103  HttpUrl m_url;
104  std::string m_requestMethod;
105  std::map<std::string, std::string> m_requestHeaders;
106  size_t m_timeout;
107  };
108 
110  {
111  public:
113  BinaryHttpRequest(const HttpUrl& url);
114 
115  const std::vector<uint8_t>* getRequestBody();
116 
117  void setRequestBody(const std::vector<uint8_t>* requestBody);
118 
119  protected:
120  virtual void read(const void*& data, size_t& length) const;
121 
122  private:
123  const std::vector<uint8_t>* m_requestBody;
124  };
125 
127  {
128  public:
130  StringHttpRequest(const HttpUrl& url);
131 
132  const std::string* getRequestBody();
133 
134  void setRequestBody(const std::string* requestBody);
135 
136  protected:
137  virtual void read(const void*& data, size_t& length) const;
138 
139  private:
140  const std::string* m_requestBody;
141  };
142 
144  {
145  public:
146  HttpResponse();
147  virtual ~HttpResponse();
148 
149  const std::string& getResponseVersion() const;
150  unsigned int getResponseCode() const;
151  const std::string& getResponseMessage() const;
152  const std::string& getResponseHeader(const std::string& key) const;
153  const std::map<std::string, std::string>& getResponseHeaders() const;
154 
155  protected:
156  virtual void write(const void* data, const size_t length);
157 
158  private:
159  template<typename T>
160  friend class HttpConnection;
161 
162  std::string m_responseVersion;
163  unsigned int m_responseCode;
164  std::string m_responseMessage;
165  std::map<std::string, std::string> m_responseHeaders;
166  };
167 
169  {
170  public:
171  const std::vector<uint8_t>& getResponseBody() const;
172 
173  protected:
174  virtual void write(const void* data, const size_t length);
175 
176  private:
177  std::vector<uint8_t> m_responseBody;
178  };
179 
181  {
182  public:
183  const std::string& getResponseBody() const;
184 
185  protected:
186  virtual void write(const void* data, const size_t length);
187 
188  private:
189  std::string m_responseBody;
190  };
191 }
192 
193 #endif
bool isSecure() const
const std::string & getProtocol() const
static const std::string POST
Definition: Http.hpp:66
std::ostream & operator<<(std::ostream &stream, const HttpUrl &value)
static const std::string HTTPS
Definition: Http.hpp:18
uint16_t getPort() const
static const std::string GET
Definition: Http.hpp:64
static const std::string HTTP
Definition: Http.hpp:17
const std::string & getHost() const
const std::string & getQuery() const
const std::string & getUrl() const
static const std::string HEAD
Definition: Http.hpp:65
const std::string & getPath() const