Crow  1.0
A C++ microframework for the web
crow::response Struct Reference

HTTP response. More...

Collaboration diagram for crow::response:

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

Public Attributes

int code {200}
 The Status code for the response. More...
 
std::string body
 The actual payload containing the response data. More...
 
ci_map headers
 HTTP headers. More...
 
bool skip_body = false
 Whether this is a response to a HEAD request. More...
 
bool manual_length_header = false
 Whether Crow should automatically add a "Content-Length" header. More...
 

Private Attributes

bool completed_ {}
 
std::function< void()> complete_request_handler_
 
std::function< bool()> is_alive_helper_
 
static_file_info file_info
 

Friends

template<typename Adaptor , typename Handler , typename... Middlewares>
class crow::Connection
 
template<typename F , typename App , typename... Middlewares>
struct crow::detail::handler_middleware_wrapper
 

Detailed Description

HTTP response.

Constructor & Destructor Documentation

◆ response() [1/10]

crow::response::response ( )
inline
Here is the caller graph for this function:

◆ response() [2/10]

crow::response::response ( int  code)
inlineexplicit

◆ response() [3/10]

crow::response::response ( std::string  body)
inline

◆ response() [4/10]

crow::response::response ( int  code,
std::string  body 
)
inline

◆ response() [5/10]

crow::response::response ( returnable &&  value)
inline
Here is the call graph for this function:

◆ response() [6/10]

crow::response::response ( returnable value)
inline
Here is the call graph for this function:

◆ response() [7/10]

crow::response::response ( int  code,
returnable value 
)
inline
Here is the call graph for this function:

◆ response() [8/10]

crow::response::response ( response &&  r)
inline

◆ response() [9/10]

crow::response::response ( std::string  contentType,
std::string  body 
)
inline
Here is the call graph for this function:

◆ response() [10/10]

crow::response::response ( int  code,
std::string  contentType,
std::string  body 
)
inline
Here is the call graph for this function:

Member Function Documentation

◆ set_header()

void crow::response::set_header ( std::string  key,
std::string  value 
)
inline

Set the value of an existing header in the response.

Here is the caller graph for this function:

◆ add_header()

void crow::response::add_header ( std::string  key,
std::string  value 
)
inline

Add a new header to the response.

Here is the caller graph for this function:

◆ get_header_value()

const std::string& crow::response::get_header_value ( const std::string &  key)
inline
Here is the call graph for this function:

◆ operator=() [1/2]

response& crow::response::operator= ( const response r)
delete

◆ operator=() [2/2]

response& crow::response::operator= ( response &&  r)
inlinenoexcept

◆ is_completed()

bool crow::response::is_completed ( ) const
inlinenoexcept

Check if the response has completed (whether response.end() has been called)

Here is the caller graph for this function:

◆ clear()

void crow::response::clear ( )
inline

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ write()

void crow::response::write ( const std::string &  body_part)
inline

◆ end() [1/2]

void crow::response::end ( )
inline

Set the response completion flag and call the handler (to send the response).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [2/2]

void crow::response::end ( const std::string &  body_part)
inline

Same as end() except it adds a body part right before ending.

Here is the call graph for this function:

◆ is_alive()

bool crow::response::is_alive ( )
inline

Check if the connection is still alive (usually by checking the socket status).

◆ is_static_type()

bool crow::response::is_static_type ( )
inline

Check whether the response has a static file defined.

◆ set_static_file_info()

void crow::response::set_static_file_info ( std::string  path)
inline

Return a static file as the response body.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_static_file_info_unsafe()

void crow::response::set_static_file_info_unsafe ( std::string  path)
inline

Return a static file as the response body without sanitizing the path (use set_static_file_info instead)

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ crow::Connection

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

◆ crow::detail::handler_middleware_wrapper

template<typename F , typename App , typename... Middlewares>
friend struct crow::detail::handler_middleware_wrapper
friend

Member Data Documentation

◆ code

int crow::response::code {200}

The Status code for the response.

◆ body

std::string crow::response::body

The actual payload containing the response data.

◆ headers

ci_map crow::response::headers

HTTP headers.

◆ skip_body

bool crow::response::skip_body = false

Whether this is a response to a HEAD request.

◆ manual_length_header

bool crow::response::manual_length_header = false

Whether Crow should automatically add a "Content-Length" header.

◆ completed_

bool crow::response::completed_ {}
private

◆ complete_request_handler_

std::function<void()> crow::response::complete_request_handler_
private

◆ is_alive_helper_

std::function<bool()> crow::response::is_alive_helper_
private

◆ file_info

static_file_info crow::response::file_info
private

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