-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathh2o-real.cc
61 lines (49 loc) · 1.97 KB
/
h2o-real.cc
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
#include "h2o-pp.hh"
#include <signal.h>
using namespace std;
int main(int argc, char** argv)
{
signal(SIGPIPE, SIG_IGN); // every TCP application needs this
// this only sets the hostname, using default ports (80, 443)
// does not yet bind to sockets
H2OWebserver h2s("live.powerdns.org");
// creates two new hosts, one on port 4430, one on port 8000
auto hostssl = h2s.addHost("www.live.powerdns.org", 4430);
auto host = h2s.addHost("www.live.powerdns.org", 8000);
// defines a handler that can be shared
auto lower = [](auto handler, auto req) {
req->res.status = 200;
req->res.reason = "OK";
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_TYPE,
NULL, H2O_STRLIT("octet/stream"));
h2o_send_inline(req, "Hallo!", 6);
return 0;
};
// we need to add this handler to both www.live.powerdns.org ports
h2s.addHandler("/een", lower, hostssl);
h2s.addHandler("/een", lower, host);
// we serve files from all hostnames
h2s.addDirectory("/files", "html/");
h2s.addDirectory("/files", "html/", host);
h2s.addDirectory("/files", "html/", hostssl);
// this is the default handler that is ONLY defined on the default
// (first) host
h2s.addHandler("/", [](auto handler, auto req) {
req->res.status = 200;
req->res.reason = "OK";
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_TYPE,
NULL, H2O_STRLIT("octet/stream"));
h2o_send_inline(req, "HALLO!", 6);
return 0;
});
auto sslactx = h2s.addSSLContext("./fullchain.pem", "./privkey.pem");
// make SSL listen on IPv4 and IPv6
h2s.addListener(ComboAddress("127.0.0.1", 443), sslactx);
h2s.addListener(ComboAddress("::1", 443), sslactx);
h2s.addListener(ComboAddress("::1", 4430), sslactx);
// and plaintext
auto actx = h2s.addContext();
h2s.addListener(ComboAddress("127.0.0.1:8000"), actx);
h2s.addListener(ComboAddress("127.0.0.1:80"), actx);
h2s.runLoop();
}