6 #include <boost/beast/http/message.hpp> 7 #include <boost/beast/http/serializer.hpp> 8 #include <boost/beast/http/string_body.hpp> 9 #include <boost/beast/http/write.hpp> 11 #include "strings/unique_strings.h" 12 #include "util/asio/connection_handler.h" 13 #include "util/http/http_common.h" 20 template <
typename FiberSyncStream>
22 template <
typename Body>
23 using Response = ::boost::beast::http::response<Body>;
24 using error_code = ::boost::system::error_code;
26 FiberSyncStream& stream_;
29 explicit SendLambda(FiberSyncStream& stream) : stream_(stream) {
32 template <
typename Body>
33 void Invoke(Response<Body>&& msg) {
40 msg.prepare_payload();
41 ::boost::beast::http::response_serializer<Body> sr{msg};
43 ::boost::beast::http::write(stream_, sr, ec);
55 typedef std::function<void(
const QueryArgs&,
SendFunction*)> RequestCb;
58 bool RegisterCb(StringPiece path,
bool protect, RequestCb cb);
65 StringPieceMap<CbInfo> cb_map_;
70 using RequestType = ::boost::beast::http::request<::boost::beast::http::string_body>;
75 boost::system::error_code HandleRequest()
final override;
79 const char* resource_prefix_;
80 virtual bool Authorize(
const QueryArgs& args)
const {
return true; }
84 void HandleRequestInternal(
const RequestType& req,
SendFunction* send);
90 template <
typename Handler = HttpHandler>
93 static_assert(std::is_base_of<HttpHandler, Handler>::value,
94 "Handler must be derived from HttpHandler");
97 return new Handler(
this, &cntx);
Abstracts away connections implementation and their life-cycle.