53 {
55
58 using Request = Client::Request;
61
63 "legacy",
64 [](const std::shared_ptr<MasterRequest>& req) {
65 VLOG(1) << "-- OnRequest";
66 req->method = "POST";
67 req->url = "/index.html";
68 req->type("application/json");
69 req->set("Connection", "close");
70 req->send(
71 "{\"userId\":1,\"schnitzel\":\"good\",\"hungry\":false}",
72 []([[maybe_unused]] const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
73 VLOG(1) << "-- OnResponse";
74 VLOG(1) << " Status:";
75 VLOG(1) << " " << res->httpVersion;
76 VLOG(1) << " " << res->statusCode;
77 VLOG(1) << " " << res->reason;
78
79 VLOG(1) << " Headers:";
80 for (const auto& [field, value] : res->headers) {
81 VLOG(1) << " " << field + " = " + value;
82 }
83
84 VLOG(1) << " Cookies:";
85 for (const auto& [name, cookie] : res->cookies) {
86 VLOG(1) << " " + name + " = " + cookie.getValue();
87 for (const auto& [option, value] : cookie.getOptions()) {
88 VLOG(1) << " " + option + " = " + value;
89 }
90 }
91
92 res->body.push_back(0);
93 VLOG(1) << " Body:\n----------- start body -----------" << res->body.data() << "------------ end body ------------";
94 },
95 [](const std::shared_ptr<Request>&, const std::string& message) {
96 VLOG(1) << "legacy: Request parse error: " << message;
97 });
98 },
99 []([[maybe_unused]] const std::shared_ptr<MasterRequest>& req) {
100 LOG(INFO) << " -- OnRequestEnd";
101 });
102
103 jsonClient.connect("localhost",
104 8080,
105 [instanceName = jsonClient.getConfig().getInstanceName()](
106 const SocketAddress& socketAddress,
108 switch (state) {
109 case core::socket::State::OK:
110 VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'";
111 break;
112 case core::socket::State::DISABLED:
113 VLOG(1) << instanceName << ": disabled";
114 break;
115 case core::socket::State::ERROR:
116 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
117 break;
118 case core::socket::State::FATAL:
119 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
120 break;
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
151
152
154}
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