author | František Kučera <franta-hg@frantovo.cz> |
Sat, 30 Apr 2022 02:49:50 +0200 | |
branch | v_0 |
changeset 8 | 90990c8b6aef |
parent 4 | 37a86904145c |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info) |
|
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, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
||
18 |
#pragma once |
|
19 |
||
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
20 |
#include <vector> |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
21 |
#include <string> |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
22 |
#include <ctype.h> |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
23 |
#include <memory> |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
24 |
|
0 | 25 |
namespace relpipe { |
26 |
namespace tr { |
|
27 |
namespace httpd { |
|
28 |
||
29 |
class HTTPServer { |
|
30 |
private: |
|
31 |
class HTTPServerImpl; |
|
32 |
HTTPServerImpl* impl; |
|
33 |
||
34 |
HTTPServer(HTTPServerImpl* impl) : impl(impl) { |
|
35 |
} |
|
36 |
||
37 |
||
38 |
public: |
|
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
39 |
|
8
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
40 |
/** Attribute-value pair – header, cookie, GET or POST parameter */ |
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
41 |
class AVP { |
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
42 |
public: |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
43 |
std::string name; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
44 |
std::string value; |
4
37a86904145c
partial implementation of response and header templates
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
45 |
|
8
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
46 |
AVP(std::string name, std::string value) : name(name), value(value) { |
4
37a86904145c
partial implementation of response and header templates
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
47 |
} |
37a86904145c
partial implementation of response and header templates
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
48 |
|
8
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
49 |
virtual ~AVP() { |
4
37a86904145c
partial implementation of response and header templates
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
50 |
} |
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
51 |
}; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
52 |
|
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
53 |
class Request { |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
54 |
public: |
8
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
55 |
std::vector<AVP> header; |
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
56 |
std::vector<AVP> cookie; |
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
57 |
std::vector<AVP> getParameter; |
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
58 |
std::vector<AVP> postParameter; |
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
59 |
std::string host; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
60 |
std::string method; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
61 |
std::string url; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
62 |
std::string body; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
63 |
}; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
64 |
|
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
65 |
class Response { |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
66 |
public: |
8
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
67 |
std::vector<AVP> header; |
90990c8b6aef
headers, cookies, GET parameters
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
68 |
std::vector<AVP> cookie; |
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
69 |
uint16_t code; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
70 |
std::string body; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
71 |
}; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
72 |
|
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
73 |
class RequestHandler { |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
74 |
public: |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
75 |
|
3
1184f3de5533
return responses from HTTPDHandler::requestHandler instead of constant ones
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
76 |
virtual const Response handle(const Request& request) = 0; |
1184f3de5533
return responses from HTTPDHandler::requestHandler instead of constant ones
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
77 |
|
1184f3de5533
return responses from HTTPDHandler::requestHandler instead of constant ones
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
78 |
virtual ~RequestHandler() = default; |
1184f3de5533
return responses from HTTPDHandler::requestHandler instead of constant ones
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
79 |
|
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
80 |
}; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
81 |
|
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
82 |
class Options { |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
83 |
public: |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
84 |
uint16_t tcpPort = 8080; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
85 |
}; |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
86 |
|
0 | 87 |
virtual ~HTTPServer(); |
88 |
HTTPServer(const HTTPServer&) = delete; |
|
89 |
HTTPServer& operator=(const HTTPServer&) = delete; |
|
90 |
||
2
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
91 |
void setRequestHandler(std::shared_ptr<RequestHandler> handler); |
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
92 |
|
4b05b16b97e6
configurable TCP listener port + RequestHandler interface
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
93 |
static HTTPServer* create(Options options); |
0 | 94 |
|
95 |
}; |
|
96 |
||
97 |
} |
|
98 |
} |
|
99 |
} |