3#include <unordered_map> 
    9#include "crow/http_request.h" 
   10#include "crow/ci_map.h" 
   11#include "crow/socket_adaptors.h" 
   12#include "crow/logging.h" 
   13#include "crow/mime_types.h" 
   14#include "crow/returnable.h" 
   19    template <
typename Adaptor, 
typename Handler, 
typename ... Middlewares>
 
   25        template <
typename Adaptor, 
typename Handler, 
typename ... Middlewares>
 
   32#ifdef CROW_ENABLE_COMPRESSION 
   33        bool compressed = 
true; 
 
   42            headers.emplace(std::move(key), std::move(value));
 
   48            headers.emplace(std::move(key), std::move(value));
 
   51        const std::string& get_header_value(
const std::string& key)
 
   53            return crow::get_header_value(
headers, key);
 
   61        response (returnable&& value)
 
   66        response (returnable& value)
 
   77        response(response&& r)
 
   82        response& operator = (
const response& r) = 
delete;
 
   84        response& operator = (response&& r) 
noexcept 
   86            body = std::move(r.body);
 
   89            completed_ = r.completed_;
 
   90            file_info = std::move(r.file_info);
 
  106            file_info = static_file_info{};
 
  130        void moved(
const std::string& location)
 
  145        void write(
const std::string& body_part)
 
  162                if (complete_request_handler_)
 
  164                    complete_request_handler_();
 
  170        void end(
const std::string& body_part)
 
  179            return is_alive_helper_ && is_alive_helper_();
 
  185            return file_info.path.size();
 
  193            std::string path = 
"";
 
  200            utility::sanitize_filename(path);
 
  201            file_info.path = path;
 
  202            file_info.statResult = stat(file_info.path.c_str(), &file_info.statbuf);
 
  203#ifdef CROW_ENABLE_COMPRESSION 
  206            if (file_info.statResult == 0)
 
  208                std::size_t last_dot = path.find_last_of(
".");
 
  209                std::string extension = path.substr(last_dot+1);
 
  210                std::string mimeType = 
"";
 
  212                this->
add_header(
"Content-length", std::to_string(file_info.statbuf.st_size));
 
  214                if (extension != 
""){
 
  215                    mimeType = mime_types[extension];
 
  219                        this-> 
add_header(
"content-Type", 
"text/plain");
 
  231            std::function<void()> complete_request_handler_;
 
  232            std::function<bool()> is_alive_helper_;
 
  233            static_file_info file_info;
 
An HTTP connection.
Definition: http_connection.h:186
 
This constains metadata (coming from the stat command) related to any static files associated with th...
Definition: http_response.h:192
 
HTTP response.
Definition: http_response.h:24
 
void end(const std::string &body_part)
Same as end() except it adds a body part right before ending.
Definition: http_response.h:170
 
void add_header(std::string key, std::string value)
Add a new header to the response.
Definition: http_response.h:46
 
bool is_head_response
Whether this is a response to a HEAD request.
Definition: http_response.h:35
 
void moved(const std::string &location)
Definition: http_response.h:130
 
void set_static_file_info(std::string path)
Return a static file as the response body.
Definition: http_response.h:199
 
bool manual_length_header
Whether Crow should automatically add a "Content-Length" header.
Definition: http_response.h:36
 
void redirect_perm(const std::string &location)
Definition: http_response.h:121
 
void moved_perm(const std::string &location)
Definition: http_response.h:139
 
bool is_completed() const noexcept
Check if the response has completed (whether response.end() has been called)
Definition: http_response.h:95
 
int code
The Status code for the response.
Definition: http_response.h:28
 
void set_header(std::string key, std::string value)
Set the value of an existing header in the response.
Definition: http_response.h:39
 
void end()
Set the response completion flag and call the handler (to send the response).
Definition: http_response.h:151
 
void redirect(const std::string &location)
Definition: http_response.h:112
 
bool is_alive()
Check if the connection is still alive (usually by checking the socket status).
Definition: http_response.h:177
 
ci_map headers
HTTP headers.
Definition: http_response.h:30
 
std::string body
The actual payload containing the response data.
Definition: http_response.h:29
 
bool is_static_type()
Check whether the response has a static file defined.
Definition: http_response.h:183