Arbiter  0.0.0
http.hpp
1 #pragma once
2 
3 #include <vector>
4 #include <memory>
5 
6 #ifndef ARBITER_IS_AMALGAMATION
7 #include <arbiter/util/http.hpp>
8 #include <arbiter/driver.hpp>
9 #endif
10 
11 #ifdef ARBITER_CUSTOM_NAMESPACE
12 namespace ARBITER_CUSTOM_NAMESPACE
13 {
14 #endif
15 
16 namespace arbiter
17 {
18 namespace drivers
19 {
20 
29 class Http : public Driver
30 {
31 public:
32  Http(http::Pool& pool);
33  static std::unique_ptr<Http> create(
34  http::Pool& pool,
35  const Json::Value& json);
36 
37  // Inherited from Driver.
38  virtual std::string type() const override { return "http"; }
39 
43  virtual std::unique_ptr<std::size_t> tryGetSize(
44  std::string path) const override;
45 
46  virtual void put(
47  std::string path,
48  const std::vector<char>& data) const final override
49  {
50  put(path, data, http::Headers(), http::Query());
51  }
52 
53  /* HTTP-specific driver methods follow. Since many drivers (S3, Dropbox,
54  * etc.) are built atop HTTP, we'll provide HTTP-specific methods for
55  * derived classes to use in addition to the generic PUT/GET combinations.
56  *
57  * Specifically, we'll add POST/HEAD calls, and allow headers and query
58  * parameters to be passed as well.
59  */
60 
62  std::string get(
63  std::string path,
64  http::Headers headers,
65  http::Query query) const;
66 
68  std::unique_ptr<std::string> tryGet(
69  std::string path,
70  http::Headers headers,
71  http::Query query) const;
72 
74  std::vector<char> getBinary(
75  std::string path,
76  http::Headers headers,
77  http::Query query) const;
78 
80  std::unique_ptr<std::vector<char>> tryGetBinary(
81  std::string path,
82  http::Headers headers,
83  http::Query query) const;
84 
86  void put(
87  std::string path,
88  const std::string& data,
89  http::Headers headers,
90  http::Query query) const;
91 
97  virtual void put(
98  std::string path,
99  const std::vector<char>& data,
100  http::Headers headers,
101  http::Query query) const;
102 
103 protected:
107  virtual bool get(
108  std::string path,
109  std::vector<char>& data,
110  http::Headers headers,
111  http::Query query) const;
112 
113  /* These operations are other HTTP-specific calls that derived drivers may
114  * need for their underlying API use.
115  */
116  http::Response internalGet(
117  std::string path,
118  http::Headers headers = http::Headers(),
119  http::Query query = http::Query()) const;
120 
121  http::Response internalPut(
122  std::string path,
123  const std::vector<char>& data,
124  http::Headers headers = http::Headers(),
125  http::Query query = http::Query()) const;
126 
127  http::Response internalHead(
128  std::string path,
129  http::Headers headers = http::Headers(),
130  http::Query query = http::Query()) const;
131 
132  http::Response internalPost(
133  std::string path,
134  const std::vector<char>& data,
135  http::Headers headers = http::Headers(),
136  http::Query query = http::Query()) const;
137 
138 private:
139  virtual bool get(
140  std::string path,
141  std::vector<char>& data) const final override
142  {
143  return get(path, data, http::Headers(), http::Query());
144  }
145 
146  http::Pool& m_pool;
147 };
148 
149 } // namespace drivers
150 } // namespace arbiter
151 
152 #ifdef ARBITER_CUSTOM_NAMESPACE
153 }
154 #endif
155 
virtual std::string type() const override
Definition: http.hpp:38
Base class for interacting with a storage type.
Definition: driver.hpp:34
HTTP driver. Intended as both a standalone driver as well as a base for derived drivers build atop HT...
Definition: http.hpp:29
Definition: arbiter.cpp:16
virtual void put(std::string path, const std::vector< char > &data) const final override
Definition: http.hpp:46