request.h
1 /*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2021 <copyright holder> <email>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef ATOM_HTTP_REQUEST
20 #define ATOM_HTTP_REQUEST
21 
22 
23 #include <vector>
24 #include <optional>
25 
26 #include <Poco/Net/HTTPServerRequest.h>
27 #include <Poco/Net/HTTPServerResponse.h>
28 #include <Poco/Net/HTTPCookie.h>
29 #include <Poco/Net/NameValueCollection.h>
30 
31 
32 namespace Atom
33 {
34  namespace HTTP
35  {
36  class Header;
37  class Cookie;
38  class Request;
39  }
40 }
41 
42 using namespace Poco;
43 using namespace Poco::Net;
44 
45 
46 
48 {
49  public:
50  Header(std::string name, std::string value) :
51  name(name)
52  ,value(value)
53  {}
54  virtual ~Header(){}
55 
56  std::string name;
57  std::string value;
58 };
59 
61 {
62  public:
63  Cookie(std::string name, std::string value) :
64  name(name)
65  ,value(value)
66  {}
67  virtual ~Cookie(){}
68 
69  std::string name;
70  std::string value;
71 };
72 
74 {
75  public:
76  using HTTPServerRequestPtr = std::optional<HTTPServerRequest*>;
77  using HTTPServerResponsePtr = std::optional<HTTPServerResponse*>;
78 
79  Request();
80 
81  HTTPServerRequestPtr& get_http_server_request()
82  {
83  auto& var = http_server_request_;
84  return var;
85  }
86  HTTPServerResponsePtr& get_http_server_response()
87  {
88  auto& var = http_server_response_;
89  return var;
90  }
91  std::vector<HTTP::Header> get_headers()
92  {
93  auto& var = headers_;
94  return var;
95  }
96  std::vector<HTTP::Cookie> get_cookies()
97  {
98  auto& var = cookies_;
99  return var;
100  }
101  std::string get_uri() const { return uri_; }
102  std::string get_method() const { return method_; }
103  std::string get_content_type() const { return content_type_; };
104  Net::NameValueCollection get_content_type_parameters() const { return content_type_parameters_; };
105 
106  void AddHeader_(std::string name, std::string value);
107  void AddCookie_(std::string name, std::string value);
108 
109  protected:
110  void SetupRequest_(Net::HTTPServerRequest& request);
111  void SetupResponse_(Net::HTTPServerResponse& response);
112  void SetupHeaders_();
113  void SetupCookies_();
114 
115  private:
116  HTTPServerRequestPtr http_server_request_;
117  HTTPServerResponsePtr http_server_response_;
118  std::vector<HTTP::Header> headers_;
119  std::vector<HTTP::Cookie> cookies_;
120  std::string uri_;
121  std::string method_;
122  std::string content_type_;
123  Net::NameValueCollection content_type_parameters_;
124 };
125 
126 #endif // ATOM_HTTP_REQUEST
Definition: request.h:61
Definition: request.h:48
Definition: request.h:74