7 #include <boost/beast/http/serializer.hpp> 8 #include <boost/beast/http/write.hpp> 10 #include "util/uring/accept_server.h" 11 #include "strings/unique_strings.h" 12 #include "util/http/http_common.h" 18 template <
typename Body>
19 using Response = ::boost::beast::http::response<Body>;
20 using error_code = ::boost::system::error_code;
27 template <
typename Body>
void Invoke(Response<Body>&& msg) {
34 msg.prepare_payload();
35 ::boost::beast::http::response_serializer<Body> sr{msg};
37 ::boost::system::error_code ec;
38 ::boost::beast::http::write(asa_, sr, ec);
51 using RequestType = ::boost::beast::http::request<::boost::beast::http::string_body>;
52 typedef std::function<void(
const http::QueryArgs&,
HttpContext*)> RequestCb;
57 bool RegisterCb(StringPiece path, RequestCb cb);
59 void set_resource_prefix(
const char* prefix) { resource_prefix_ = prefix; }
60 void set_favicon(
const char* favicon) { favicon_ = favicon;}
63 bool HandleRoot(
const RequestType& rt,
HttpContext* cntx)
const;
68 StringPieceMap<CbInfo> cb_map_;
71 const char* resource_prefix_;
76 using RequestType = ::boost::beast::http::request<::boost::beast::http::string_body>;
80 void HandleRequests()
final;
83 void HandleOne(
const RequestType& req,
HttpContext* cntx);
90 template <
typename Handler = HttpHandler2>
93 static_assert(std::is_base_of<HttpHandler2, Handler>::value,
94 "Handler must be derived from HttpHandler");
97 return new Handler(
this);
Connection * NewConnection(Proactor *) final
Abstracts away connections implementation and their life-cycle.