diff options
author | Gabriel Marinho <gabrielbiga@me.com> | 2015-04-13 01:23:45 -0300 |
---|---|---|
committer | Gabriel Marinho <gabrielbiga@me.com> | 2015-04-13 01:23:45 -0300 |
commit | b7a7df0412ef0e92e1d8d4a3763a066a9b197671 (patch) | |
tree | 36c35e36b77f37ed482421c85367684efad43aae /include/http_response.h | |
parent | db932564646921a29ffde96c85bab67381017f4a (diff) | |
download | crow-b7a7df0412ef0e92e1d8d4a3763a066a9b197671.tar.gz crow-b7a7df0412ef0e92e1d8d4a3763a066a9b197671.zip |
Fix Content-Type not setted passing JSON object by rvalue reference.
In this specific case, Crow is not setting the JSON Content-Type and this is causing "not well-formed" exception in the Firefox browser.
Diffstat (limited to 'include/http_response.h')
-rw-r--r-- | include/http_response.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/include/http_response.h b/include/http_response.h index 6e22418..c84856b 100644 --- a/include/http_response.h +++ b/include/http_response.h @@ -40,11 +40,14 @@ namespace crow 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(json::wvalue&& json_value) : json_value(std::move(json_value)) + { + json_mode(); + } response(int code, std::string body) : body(std::move(body)), code(code) {} response(const json::wvalue& json_value) : body(json::dump(json_value)) { - set_header("Content-Type", "application/json"); + json_mode(); } response(response&& r) @@ -111,5 +114,11 @@ namespace crow bool completed_{}; std::function<void()> complete_request_handler_; std::function<bool()> is_alive_helper_; + + //In case of a JSON object, set the Content-Type header + void json_mode() + { + set_header("Content-Type", "application/json"); + } }; } |