MCPcopy Create free account
hub / github.com/azadkuh/qhttp / process

Method process

example/keep-alive/main.cpp:138–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 }
137
138 void process(QHttpRequest* req, QHttpResponse* res) {
139 auto root = QJsonDocument::fromJson(req->collectedData()).object();
140
141 if ( root.isEmpty() || root.value("name").toString() != QLatin1Literal("add") ) {
142 const static char KMessage[] = "Invalid json format!";
143 res->setStatusCode(qhttp::ESTATUS_BAD_REQUEST);
144 res->addHeader("connection", "close");
145 res->addHeaderValue("content-length", strlen(KMessage));
146 res->end(KMessage);
147 return;
148 }
149
150 int total = 0;
151 auto args = root.value("args").toArray();
152 for ( const auto jv : args ) {
153 total += jv.toInt();
154 }
155 root["args"] = total;
156
157 QByteArray body = QJsonDocument(root).toJson();
158 res->addHeader("connection", "keep-alive");
159 res->addHeaderValue("content-length", body.length());
160 res->setStatusCode(qhttp::ESTATUS_OK);
161 res->end(body);
162 }
163}; // struct server
164///////////////////////////////////////////////////////////////////////////////
165} // namespace server

Callers 2

mainFunction · 0.80
mainFunction · 0.80

Calls 4

toStringMethod · 0.80
setStatusCodeMethod · 0.80
addHeaderMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected