Loading...
Searching...
No Matches
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
32namespace NAF
33{
34 namespace HTTP
35 {
36 class Header;
37 class Cookie;
38 class Request;
39 }
40}
41
42using namespace Poco;
43using 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 Cookie(Net::HTTPCookie cookie) :
68 name("")
69 ,value("")
70 ,cookie(cookie)
71 {}
72 virtual ~Cookie(){}
73
74 std::string name;
75 std::string value;
76 Net::HTTPCookie cookie;
77};
78
80{
81 public:
82 using HTTPServerRequestPtr = std::optional<HTTPServerRequest*>;
83 using HTTPServerResponsePtr = std::optional<HTTPServerResponse*>;
84
85 Request();
86
87 HTTPServerRequestPtr& get_http_server_request()
88 {
89 auto& var = http_server_request_;
90 return var;
91 }
92 HTTPServerResponsePtr& get_http_server_response()
93 {
94 auto& var = http_server_response_;
95 return var;
96 }
97 std::vector<HTTP::Header> get_headers()
98 {
99 auto& var = headers_;
100 return var;
101 }
102 std::vector<HTTP::Cookie> get_cookies()
103 {
104 auto& var = cookies_;
105 return var;
106 }
107
108 void AddHeader_(std::string name, std::string value);
109 void AddHeader_(HTTP::Header header);
110 void AddCookie_(std::string name, std::string value);
111 void AddCookie_(HTTP::Cookie cookie);
112
113 protected:
114 void SetupRequest_(Net::HTTPServerRequest& request);
115 void SetupResponse_(Net::HTTPServerResponse& response);
116 void SetupHeaders_();
117 void SetupCookies_();
118
119 private:
120 HTTPServerRequestPtr http_server_request_;
121 HTTPServerResponsePtr http_server_response_;
122 std::vector<HTTP::Header> headers_;
123 std::vector<HTTP::Cookie> cookies_;
124};
125
126#endif // NAF_HTTP_REQUEST
Definition request.h:61
Definition request.h:48
Definition request.h:80