From 3081e4e1a82a4efd8feff68850c4cc04af230cd7 Mon Sep 17 00:00:00 2001 From: ipknHama Date: Wed, 21 Sep 2016 23:11:06 +0900 Subject: Cleanup include folder into crow subfolder - only crow.h is exposed now --- include/http_response.h | 128 ------------------------------------------------ 1 file changed, 128 deletions(-) delete mode 100644 include/http_response.h (limited to 'include/http_response.h') diff --git a/include/http_response.h b/include/http_response.h deleted file mode 100644 index 23f312a..0000000 --- a/include/http_response.h +++ /dev/null @@ -1,128 +0,0 @@ -#pragma once -#include -#include -#include "json.h" -#include "http_request.h" -#include "ci_map.h" - -namespace crow -{ - template - class Connection; - struct response - { - template - friend class crow::Connection; - - int code{200}; - std::string body; - json::wvalue json_value; - - // `headers' stores HTTP headers. - ci_map headers; - - void set_header(std::string key, std::string value) - { - headers.erase(key); - headers.emplace(std::move(key), std::move(value)); - } - void add_header(std::string key, std::string value) - { - headers.emplace(std::move(key), std::move(value)); - } - - const std::string& get_header_value(const std::string& key) - { - return crow::get_header_value(headers, key); - } - - - 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)) - { - json_mode(); - } - response(int code, std::string body) : code(code), body(std::move(body)) {} - response(const json::wvalue& json_value) : body(json::dump(json_value)) - { - json_mode(); - } - response(int code, const json::wvalue& json_value) : code(code), body(json::dump(json_value)) - { - json_mode(); - } - - response(response&& r) - { - *this = std::move(r); - } - - response& operator = (const response& r) = delete; - - response& operator = (response&& r) noexcept - { - body = std::move(r.body); - json_value = std::move(r.json_value); - code = r.code; - headers = std::move(r.headers); - completed_ = r.completed_; - return *this; - } - - bool is_completed() const noexcept - { - return completed_; - } - - void clear() - { - body.clear(); - json_value.clear(); - code = 200; - headers.clear(); - completed_ = false; - } - - void write(const std::string& body_part) - { - body += body_part; - } - - void end() - { - if (!completed_) - { - completed_ = true; - - if (complete_request_handler_) - { - complete_request_handler_(); - } - } - } - - void end(const std::string& body_part) - { - body += body_part; - end(); - } - - bool is_alive() - { - return is_alive_helper_ && is_alive_helper_(); - } - - private: - 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