24#include <seastar/http/handlers.hh>
26#include <seastar/json/json_elements.hh>
36typedef std::function<sstring(const_req req)> request_function;
41typedef std::function<sstring(const_req req, http::reply&)> handle_function;
48typedef std::function<json::json_return_type(const_req req)> json_request_function;
56 future<json::json_return_type>(std::unique_ptr<http::request> req)> future_json_function;
59 future<std::unique_ptr<http::reply>>(std::unique_ptr<http::request> req,
60 std::unique_ptr<http::reply> rep)> future_handler_function;
72 [f_handle](std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) {
73 rep->_content += f_handle(*req.get(), *rep.get());
74 return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
78 function_handler(
const future_handler_function& f_handle,
const sstring& type)
79 : _f_handle(f_handle), _type(type) {
84 [_handle](std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) {
85 rep->_content += _handle(*req.get());
86 return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
92 [_handle](std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) {
94 rep->_content += res._res;
95 return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
101 [_handle](std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep) {
103 if (res._body_writer) {
104 rep->write_body(
"json", std::move(res._body_writer));
106 rep->_content += res._res;
117 std::unique_ptr<http::request> req, std::unique_ptr<http::reply> rep)
override {
118 return _f_handle(std::move(req), std::move(rep)).then(
119 [
this](std::unique_ptr<http::reply> rep) {
121 return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
126 future_handler_function _f_handle;
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Definition: function_handlers.hh:67
future< std::unique_ptr< http::reply > > handle(const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep) override
Definition: function_handlers.hh:116
Definition: handlers.hh:42
future< T > make_ready_future(A &&... value) noexcept
Creates a future in an available, value state.
Definition: future.hh:1943
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: json_elements.hh:299