From 88cc6079cb2ba9790a2d8bb9a5955006bfcc7a16 Mon Sep 17 00:00:00 2001 From: ipknHama Date: Tue, 5 Aug 2014 22:38:51 +0900 Subject: add supporing handlers with res parameter void handler(const crow::request&, crow::response& res) { res.send(data) res.end() } https://news.ycombinator.com/item?id=8004017 --- http_response.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'http_response.h') diff --git a/http_response.h b/http_response.h index 392fe9c..eff1d0f 100644 --- a/http_response.h +++ b/http_response.h @@ -11,16 +11,19 @@ namespace crow json::wvalue json_value; int code{200}; std::unordered_map headers; + response() {} explicit response(int code) : code(code) {} response(std::string body) : body(std::move(body)) {} response(json::wvalue&& json_value) : json_value(std::move(json_value)) {} response(const json::wvalue& json_value) : body(json::dump(json_value)) {} response(int code, std::string body) : body(std::move(body)), code(code) {} + response(response&& r) { *this = std::move(r); } + response& operator = (response&& r) { body = std::move(r.body); @@ -29,5 +32,20 @@ namespace crow headers = std::move(r.headers); return *this; } + + void send(const std::string& body_part) + { + body += body_part; + } + + void end() + { + } + + void end(const std::string& body_part) + { + body += body_part; + end(); + } }; } -- cgit v1.2.3-54-g00ecf