51 {
53
56 using Request = Client::Request;
59
61 "legacy",
62 [](const std::shared_ptr<MasterRequest>& req) {
63 VLOG(1) << "-- OnRequest";
64 req->method = "POST";
65 req->url = "/index.html";
66 req->type("application/json");
67 req->set("Connection", "close");
68 req->send(
69 R"({"userId":1,"schnitzel":"good","hungry":false})",
70 []([[maybe_unused]] const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
71 VLOG(1) << "-- OnResponse";
72 VLOG(1) << " Status:";
73 VLOG(1) << " " << res->httpVersion;
74 VLOG(1) << " " << res->statusCode;
75 VLOG(1) << " " << res->reason;
76
77 VLOG(1) << " Headers:";
78 for (const auto& [field, value] : res->headers) {
79 VLOG(1) << " " << field + " = " + value;
80 }
81
82 VLOG(1) << " Cookies:";
83 for (const auto& [name, cookie] : res->cookies) {
84 VLOG(1) << " " + name + " = " + cookie.getValue();
85 for (const auto& [option, value] : cookie.getOptions()) {
86 VLOG(1) << " " + option + " = " + value;
87 }
88 }
89
90 res->body.push_back(0);
91 VLOG(1) << " Body:\n----------- start body -----------" << res->body.data() << "------------ end body ------------";
92 },
93 [](const std::shared_ptr<Request>&, const std::string& message) {
94 VLOG(1) << "legacy: Request parse error: " << message;
95 });
96 },
97 []([[maybe_unused]] const std::shared_ptr<MasterRequest>& req) {
98 LOG(INFO) << " -- OnRequestEnd";
99 });
100
101 jsonClient.connect("localhost",
102 8080,
103 [instanceName = jsonClient.getConfig().getInstanceName()](
104 const SocketAddress& socketAddress,
106 switch (state) {
107 case core::socket::State::OK:
108 VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'";
109 break;
110 case core::socket::State::DISABLED:
111 VLOG(1) << instanceName << ": disabled";
112 break;
113 case core::socket::State::ERROR:
114 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
115 break;
116 case core::socket::State::FATAL:
117 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
118 break;
119 }
120 });
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
152}
static void init(int argc, char *argv[])
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Client::Response Response
web::http::legacy::NET::Client Client
Client::MasterRequest MasterRequest
SocketClient::SocketAddress SocketAddress
web::http::client::Client< net::in::stream::legacy::SocketClient > Client