33int main(
int argc,
char* argv[]) {
34 core::SNodeC::init(argc, argv);
36 using Client = web::http::legacy::in::Client;
37 using Request = Client::Request;
38 using Response = Client::Response;
39 using SocketAddress = Client::SocketAddress;
41 const Client jsonClient(
43 [](
const std::shared_ptr<Request>& req) {
44 VLOG(1) <<
"-- OnRequest";
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;
57 VLOG(1) <<
" Headers:";
58 for (
const auto& [field, value] : res->headers) {
59 VLOG(1) <<
" " << field +
" = " + value;
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;
70 res->body.push_back(0);
71 VLOG(1) <<
" Body:\n----------- start body -----------" << res->body.data()
72 <<
"------------ end body ------------";
75 []([[maybe_unused]]
const std::shared_ptr<Request>& req) {
76 LOG(INFO) <<
" -- OnRequestEnd";
79 jsonClient.connect(
"localhost",
81 [instanceName = jsonClient.getConfig().getInstanceName()](
82 const SocketAddress& socketAddress,
83 const core::socket::State& state) {
85 case core::socket::State::OK:
86 VLOG(1) << instanceName <<
": connected to '" << socketAddress.toString() <<
"'";
88 case core::socket::State::DISABLED:
89 VLOG(1) << instanceName <<
": disabled";
91 case core::socket::State::ERROR:
92 LOG(ERROR) << instanceName <<
": " << socketAddress.toString() <<
": " << state.what();
94 case core::socket::State::FATAL:
95 LOG(FATAL) << instanceName <<
": " << socketAddress.toString() <<
": " << state.what();
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
122
123
124
125
126
127
129 return core::SNodeC::start();