-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
91 lines (69 loc) · 3.74 KB
/
test.cpp
File metadata and controls
91 lines (69 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <string>
#include <boost/asio.hpp>
#include <beast/http.hpp>
#include <araignee.h>
#include <araignee/url_match_cast.h>
#include <araignee/redirect.h>
#include <araignee/not_found_handler.h>
#include <araignee/static_files.h>
#include <araignee/http_response.h>
#include <araignee/extract_parameters.h>
#include <araignee/http_templated_response.h>
using namespace std::literals::string_literals;
namespace app {
template<typename AsyncWriteStream>
auto foo(araingee::http_response<beast::http::string_body, beast::http::headers, AsyncWriteStream> resp,
int foo, std::string&& more_foo)
-> araingee::http_response<beast::http::string_body, beast::http::headers, AsyncWriteStream> {
resp.status = 200;
resp.reason = beast::http::reason_string(200);
auto foo_text = boost::lexical_cast<std::string>(foo) + "_" + more_foo;
resp.body = "<html><head><title>foo: "s + foo_text + "</title></head><body>foo: "s + foo_text + "</body></html>"s;
resp.headers.replace("Content-Length", resp.body.size());
resp.headers.replace("Content-Type", "text/html");
return resp;
}
class bar {
public:
template<typename AsyncWriteStream>
auto operator () (araingee::http_response<beast::http::string_body, beast::http::headers, AsyncWriteStream> resp,
std::string&& bar_text)
-> araingee::http_response<beast::http::string_body, beast::http::headers, AsyncWriteStream> {
resp.status = 200;
resp.reason = beast::http::reason_string(200);
resp.headers.replace("Content-Type", "text/html");
resp.body = "<html><head><title>bar: "s + bar_text + "</title></head><body>bar: "s + bar_text + "</body></html>"s;
resp.headers.replace("Content-Length", resp.body.size());
return resp;
};
};
class baz {
public:
template<typename AsyncWriteStream>
auto operator () (araingee::http_response<beast::http::string_body, beast::http::headers, AsyncWriteStream> resp,
double baz)
-> araingee::http_response<beast::http::string_body, beast::http::headers, AsyncWriteStream> {
resp.status = 200;
resp.reason = beast::http::reason_string(200);
resp.headers.replace("Content-Type", "text/html");
auto baz_text = boost::lexical_cast<std::string>(baz);
resp.body = "<html><head><title>baz: "s + baz_text + "</title></head><body>baz: "s + baz_text + "</body></html>"s;
resp.headers.replace("Content-Length", resp.body.size());
return resp;
};
};
}
int main(int, char**) {
using namespace araingee;
auto appRoute = route_url(route("^/foo/([0-9]+)_(.*)"s, extract_parameters(app::foo<boost::asio::ip::tcp::socket>,
url_match_cast<int>{"$1"s},
url_match_cast<std::string>{"asdf: $2"s}))/*,
route("^/bar/([a-fA-F0-9]*)"s, app::bar{"$1"s}),
route("^/baz/([0-9]*([.][0-9]+)?)", app::baz{"$1"s})*/);
auto r = route_url(route("^/oldAppBase(.*)$"s, redirect("/newAppBase$1"s)),
route("^/newAppBase(.*)$"s, appRoute("$1"s)),
/*route("^/webSockets(.*)$"s, sockHandler{"$1"s}),
route("^/otherWebSockets(.*)$"s, otherSockHandler{"$1"s}),*/
route("^/static(.*)$"s, static_file_handler{boost::filesystem::current_path(), "$1"s}));
return 0;
}