diff options
author | ipknHama <ipknhama@gmail.com> | 2014-08-05 22:38:51 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2014-08-06 04:07:46 +0900 |
commit | 88cc6079cb2ba9790a2d8bb9a5955006bfcc7a16 (patch) | |
tree | 10d89cf3d7f4754acc5f61674f16889ca73f01cb /http_response.h | |
parent | 9e331deaeecb619221cc0c59c69f14c77bb7c8a4 (diff) | |
download | crow-88cc6079cb2ba9790a2d8bb9a5955006bfcc7a16.tar.gz crow-88cc6079cb2ba9790a2d8bb9a5955006bfcc7a16.zip |
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
Diffstat (limited to 'http_response.h')
-rw-r--r-- | http_response.h | 18 |
1 files changed, 18 insertions, 0 deletions
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<std::string, std::string> 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(); + } }; } |