| 35 | // -- API for the responders --------------------------------------------------- |
| 36 | |
| 37 | request router::lift(responder&& res) { |
| 38 | auto prom = async::promise<response>(); |
| 39 | auto fut = prom.get_future(); |
| 40 | auto buf = std::vector<std::byte>{res.payload().begin(), res.payload().end()}; |
| 41 | auto lifted = request{res.header(), std::move(buf), std::move(prom)}; |
| 42 | auto request_id = request_id_++; |
| 43 | auto hdl = fut.bind_to(down_->mpx()) |
| 44 | .then( |
| 45 | [this, request_id](const response& res) { |
| 46 | down_->begin_header(res.code()); |
| 47 | for (auto& [key, val] : res.header_fields()) |
| 48 | down_->add_header_field(key, val); |
| 49 | std::ignore = down_->end_header(); |
| 50 | down_->send_payload(res.body()); |
| 51 | pending_.erase(request_id); |
| 52 | }, |
| 53 | [this, request_id](const error& err) { |
| 54 | auto description = to_string(err); |
| 55 | down_->send_response(status::internal_server_error, |
| 56 | "text/plain", description); |
| 57 | pending_.erase(request_id); |
| 58 | }); |
| 59 | pending_.emplace(request_id, std::move(hdl)); |
| 60 | return lifted; |
| 61 | } |
| 62 | |
| 63 | void router::shutdown(const error& err) { |
| 64 | abort_and_shutdown(err); |
no test coverage detected