This repository was archived by the owner on Sep 21, 2018. It is now read-only.
forked from Milerius/sza
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTest1.cpp
More file actions
93 lines (73 loc) · 2.19 KB
/
Test1.cpp
File metadata and controls
93 lines (73 loc) · 2.19 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
90
91
92
93
//
// Created by scorsi on 23/12/17.
//
#include <iostream>
#include "api/pp/conf.hpp"
#include "api/pp/net.hpp"
#include "api/pp/http.hpp"
#include "api/pp/module.hpp"
// SZA++ Module Implementation
class Test : public zia::apipp::Module {
public:
~Test() override = default;
bool perform() override {
this->response->useStandardData();
this->response
->setStatus(200, "OK")
->addHeader("Set-Cookie", "test")
->addHeader("Set-Cookie", "toto")
->setStandardData("test");
return true;
}
};
// Basic SZA Module Implementation
class BasicTest : public zia::api::Module {
private:
zia::api::Conf conf;
public:
~BasicTest() override = default;
bool config(const zia::api::Conf &conf) override {
this->conf = conf;
return true;
}
bool exec(zia::api::HttpDuplex &duplex) override {
duplex.resp.status = 200;
duplex.resp.reason = "OK";
duplex.resp.headers["Set-Cookie"] = "test";
duplex.resp.headers["Set-Cookie"] += ", toto";
for (const auto &item: "test") {
duplex.resp.body.push_back(static_cast<std::byte>(item));
}
duplex.resp.body.pop_back(); // Remove useless \0 caused by the foreach loop
return true;
}
};
void test1() {
{
// SZA++ Example
Test module = Test();
zia::api::HttpDuplex duplex;
module.exec(duplex);
for (const auto &item: duplex.resp.body) {
std::cout << static_cast<char>(item);
}
std::cout << std::endl;
for (const auto &item: duplex.resp.headers) {
std::cout << item.first << "=" << item.second << std::endl;
}
}
{
// Basic SZA Example
BasicTest module = BasicTest();
zia::api::HttpDuplex duplex;
module.exec(duplex);
for (const auto &item: duplex.resp.body) {
std::cout << static_cast<char>(item);
}
std::cout << std::endl;
for (const auto &item: duplex.resp.headers) {
std::cout << item.first << "=" << item.second << std::endl;
}
}
std::cout << std::endl << std::endl;
}