rikitiki
v0.1.67
Build C++ web server modules that allow easy routing and deployment.
Main Page
Related Pages
Classes
Files
File List
headersTest.h
1
/* Copyright (C) 2012-2013 Justin Berger
2
The full license is available in the LICENSE file at the root of this project and is also available at http://opensource.org/licenses/MIT. */
3
4
#include <rikitiki/rikitiki>
5
#include <rikitiki/mongoose/server.h>
6
#include <rikitiki/configuration/configuration>
7
8
9
using namespace
rikitiki;
10
using namespace
rikitiki::mongoose;
11
12
namespace
rikitiki {
13
namespace
examples {
14
18
struct
HeadersTestModule
{
19
void
Register(
Server
& server){
20
typedef
HeadersTestModule
T;
21
server.AddHandler(
CreateRoute<>::With
(
this
,
"/headers"
, &T::headers) );
22
server.AddHandler(
CreateRoute<std::string, std::string>::With
(
this
,
"/cookies/{name}/{value}"
, &T::set_cookie) );
23
server.AddHandler(
CreateRoute<>::With
(
this
,
"/cookies"
, &T::cookies) );
24
}
25
26
void
headers(
ConnContext
& ctx){
27
ctx << ContentType::text_plain
28
<<
"Headers: \n"
;
29
for
(
auto
header : ctx.Headers())
30
ctx << header.first <<
": "
<< header.second <<
"\n"
;
31
}
32
33
void
cookies(
ConnContext
& ctx){
34
if
(ctx.QueryString()[
"name"
].size())
35
ctx <<
Cookie
(ctx.QueryString()[
"name"
], ctx.QueryString()[
"value"
]);
36
37
ctx << ContentType::text_plain
38
<<
"Cookies: \n"
;
39
40
for
(
auto
cook : ctx.Cookies())
41
ctx << cook.first <<
": "
<< cook.second <<
"\n"
;
42
ctx <<
"Headers: \n"
;
43
for
(
auto
header : ctx.Headers())
44
ctx << header.first <<
": "
<< header.second <<
"\n"
;
45
}
46
47
void
set_cookie(
ConnContext
& ctx,
const
std::string& name,
const
std::string& value){
48
ctx <<
Cookie
(name, value)
49
<<
"<a href='/cookies/test/test'>test</a>\n"
;
50
}
51
};
52
}
53
}
include
rikitiki
examples
headersTest.h
Generated on Mon Apr 1 2013 18:17:04 for rikitiki by
1.8.3.1