# Crow: crow::response Struct Reference

Loading...
Searching...
No Matches
crow::response Struct Reference

HTTP response. More...

`#include <http_response.h>`

## Classes

struct | static_file_info
| This constains metadata (coming from the `stat` command) related to any static files associated with this response. More...

## Public Member Functions

void | set_header (std::string key, std::string value)
| Set the value of an existing header in the response.
void | add_header (std::string key, std::string value)
| Add a new header to the response.
const std::string & | get_header_value (const std::string &key)
| response (int code)
| response (std::string body)
| response (int code, std::string body)
| response (returnable &&value)
| response (returnable &value)
| response (int code, returnable &value)
| response (int code, returnable &&value)
| response (response &&r)
| response (std::string contentType, std::string body)
| response (int code, std::string contentType, std::string body)
response & | operator= (const response &r)=delete
response & | operator= (response &&r) noexcept
bool | is_completed () const noexcept
| Check if the response has completed (whether response.end() has been called)
void | clear ()
void | redirect (const std::string &location)
| Return a "Temporary Redirect" response.
void | redirect_perm (const std::string &location)
| Return a "Permanent Redirect" response.
void | moved (const std::string &location)
| Return a "Found (Moved Temporarily)" response.
void | moved_perm (const std::string &location)
| Return a "Moved Permanently" response.
void | write (const std::string &body_part)
void | end ()
| Set the response completion flag and call the handler (to send the response).
void | end (const std::string &body_part)
| Same as end() except it adds a body part right before ending.
bool | is_alive ()
| Check if the connection is still alive (usually by checking the socket status).
bool | is_static_type ()
| Check whether the response has a static file defined.
void | set_static_file_info (std::string path)
| Return a static file as the response body.
void | set_static_file_info_unsafe (std::string path)
| Return a static file as the response body without sanitizing the path (use set_static_file_info instead)

## Static Public Member Functions

static bool | validate_mime_type (const std::string &candidate) noexcept
static std::string | get_mime_type (const std::string &contentType)

## Public Attributes

int | code {200}
| The Status code for the response.
std::string | body
| The actual payload containing the response data.
ci_map | headers
| HTTP headers.
bool | compressed = true
| If compression is enabled and this is false, the individual response will not be compressed.
bool | skip_body = false
| Whether this is a response to a HEAD request.
bool | manual_length_header = false
| Whether Crow should automatically add a "Content-Length" header.

## Friends

template<typename Adaptor , typename Handler , typename... Middlewares>
class | crow::Connection
class | Router

## Detailed Description

HTTP response.

## Member Function Documentation

## moved()

void crow::response::moved | ( | const std::string & | location | ) |

inline

Return a "Found (Moved Temporarily)" response.

Location can either be a route or a full URL.

## moved_perm()

void crow::response::moved_perm | ( | const std::string & | location | ) |

inline

Return a "Moved Permanently" response.

Location can either be a route or a full URL.

## redirect()

void crow::response::redirect | ( | const std::string & | location | ) |

inline

Return a "Temporary Redirect" response.

Location can either be a route or a full URL.

## redirect_perm()

void crow::response::redirect_perm | ( | const std::string & | location | ) |

inline

Return a "Permanent Redirect" response.

Location can either be a route or a full URL.

The documentation for this struct was generated from the following file:

- include/crow/http_response.h