From b7a7df0412ef0e92e1d8d4a3763a066a9b197671 Mon Sep 17 00:00:00 2001 From: Gabriel Marinho Date: Mon, 13 Apr 2015 01:23:45 -0300 Subject: 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. --- include/http_response.h | 13 +++++++++++-- 1 file 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 complete_request_handler_; std::function is_alive_helper_; + + //In case of a JSON object, set the Content-Type header + void json_mode() + { + set_header("Content-Type", "application/json"); + } }; } -- cgit v1.2.3-54-g00ecf