MCPcopy Create free account
hub / github.com/bcndev/bytecoin / on_client_handle_request

Method on_client_handle_request

src/http/Server.cpp:205–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205void Server::on_client_handle_request(Client *who, RequestBody &&request) {
206 ResponseBody response(request.r);
207 response.r.status = 422;
208 response.set_body(std::string{});
209
210 bool result = true;
211 try {
212 result = r_handler(who, std::move(request), response);
213 } catch (const ErrorAuthorization &e) {
214 std::cout << "HTTP unauthorized request" << std::endl;
215 response.r.headers.push_back({"WWW-Authenticate", "Basic realm=\"" + e.realm + "\", charset=\"UTF-8\""});
216 response.r.status = 401;
217 } catch (const std::exception &e) {
218 std::cout << "HTTP request leads to throw/catch, what=" << common::what(e) << std::endl;
219 response.r.status = 422;
220 response.set_body(common::what(e));
221 } catch (...) {
222 std::cout << "HTTP request leads to throw/catch" << std::endl;
223 response.r.status = 422;
224 }
225 if (result)
226 who->write(std::move(response));
227}

Callers

nothing calls this directly

Calls 2

set_bodyMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected