33 {
35
37 using Request = Client::Request;
40
42 "legacy",
43 [](const std::shared_ptr<Request>& req) {
44 VLOG(1) << "-- OnRequest";
45 req->method = "POST";
46 req->url = "/index.html";
47 req->type("application/json");
48 req->set("Connection", "close");
49 req->send("{\"userId\":1,\"schnitzel\":\"good\",\"hungry\":false}",
50 []([[maybe_unused]] const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
51 VLOG(1) << "-- OnResponse";
52 VLOG(1) << " Status:";
53 VLOG(1) << " " << res->httpVersion;
54 VLOG(1) << " " << res->statusCode;
55 VLOG(1) << " " << res->reason;
56
57 VLOG(1) << " Headers:";
58 for (const auto& [field, value] : res->headers) {
59 VLOG(1) << " " << field + " = " + value;
60 }
61
62 VLOG(1) << " Cookies:";
63 for (const auto& [name, cookie] : res->cookies) {
64 VLOG(1) << " " + name + " = " + cookie.getValue();
65 for (const auto& [option, value] : cookie.getOptions()) {
66 VLOG(1) << " " + option + " = " + value;
67 }
68 }
69
70 res->body.push_back(0);
71 VLOG(1) << " Body:\n----------- start body -----------" << res->body.data()
72 << "------------ end body ------------";
73 });
74 },
75 []([[maybe_unused]] const std::shared_ptr<Request>& req) {
76 LOG(INFO) << " -- OnRequestEnd";
77 });
78
79 jsonClient.connect("localhost",
80 8080,
81 [instanceName = jsonClient.getConfig().getInstanceName()](
84 switch (state) {
86 VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'";
87 break;
89 VLOG(1) << instanceName << ": disabled";
90 break;
92 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
93 break;
95 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
96 break;
97 }
98 });
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
130}
static void init(int argc, char *argv[])
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
static constexpr int DISABLED
static constexpr int ERROR
static constexpr int FATAL
Client::Response Response
web::http::legacy::NET::Client Client
SocketClient::SocketAddress SocketAddress
ClientBase< web::http::client::Request, web::http::client::Response > Client