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 NAF_HTTP_REQUEST
20 #define NAF_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 NAF
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 
102  void AddHeader_(std::string name, std::string value);
103  void AddCookie_(std::string name, std::string value);
104 
105  protected:
106  void SetupRequest_(Net::HTTPServerRequest& request);
107  void SetupResponse_(Net::HTTPServerResponse& response);
108  void SetupHeaders_();
109  void SetupCookies_();
110 
111  private:
112  HTTPServerRequestPtr http_server_request_;
113  HTTPServerResponsePtr http_server_response_;
114  std::vector<HTTP::Header> headers_;
115  std::vector<HTTP::Cookie> cookies_;
116 };
117 
118 #endif // NAF_HTTP_REQUEST
Definition: request.h:61
Definition: request.h:48
Definition: request.h:74