class response_builder#

class response_builder#

A type for constructing an instance of response.

Public Functions

inline explicit response_builder(http::status status)#

Construct a response_builder with specific HTTP status code.

inline auto set_status(http::status_code status) & noexcept -> response_builder&#

Set HTTP status code.

inline auto set_version(http::version version) & noexcept -> response_builder&#

Set HTTP version.

inline auto set_header(std::string_view name, std::string_view value) & -> response_builder&#

Set HTTP headers.

DESCRIPTION

Set HTTP headers. The input name will be canonicalized before insertion. Note that any existing headers with the same name will be removed before the insertion.

inline auto set_header(http::field name, std::string_view value) & -> response_builder&#

Set HTTP headers.

DESCRIPTION

Set HTTP headers. Note that any existing headers with the same name will be removed before the insertion.

inline auto insert_header(std::string_view name, std::string_view value) & -> response_builder&#

Insert HTTP headers.

DESCRIPTION

Insert HTTP headers. The input name will be canonicalized before insertion. Note that any existing headers with the same name will be kept.

inline auto insert_header(http::field name, std::string_view value) & -> response_builder&#

Insert HTTP headers.

DESCRIPTION

Insert HTTP headers. Note that any existing headers with the same name will be kept.

inline auto set_body() -> response#

Set a null body and create the response.

DESCRIPTION

Set a null body and create the response. If you do not want to modify the existing body, call build() instead. Note that current object is no longer usable after calling this function.

template<std::size_t N>
inline auto set_body(std::span<const std::byte, N> bytes) -> response#

Set a raw body and create the response.

DESCRIPTION

Set a raw body and create the response. Note that current object is no longer usable after calling this function.

inline auto set_body(std::string_view sv) -> response#

Set a raw body and create the response.

DESCRIPTION

Set a raw body and create the response. Note that current object is no longer usable after calling this function.

template<async_readable_stream AsyncReadableStream>
inline auto set_body(AsyncReadableStream &&stream) -> response#

Set a raw body and create the response.

DESCRIPTION

Set a raw body and create the response. Note that current object is no longer usable after calling this function.

inline auto set_json(const boost::json::value &jv) -> response#

Set a json object as the body and create the response.

DESCRIPTION

Set a json object as the body and create the response. Content-Type: application/json will be automatically inserted. Note that current object is no longer usable after calling this function.

template<typename T>
inline auto set_json(const T &obj) -> response#

Set an object of type T that is converiable to a json object as the body and create the response.

DESCRIPTION

Set an object of type T that is converiable to a json object as the the body and create the response. Content-Type: application/json will be automatically inserted. Note that current object is no longer usable after calling this function.

template<async_readable_stream AsyncReadableStream>
inline auto set_stream_body(AsyncReadableStream &&stream) -> response#

Set a stream body and create the response.

DESCRIPTION

Set a stream body and create the response. A stream body will be sent with Transfer-Encoding: chunked. Note that current object is no longer usable after calling this function.

inline auto build() -> response#

Do not modify the body and create the response.

DESCRIPTION

Do not modify the body and create the response. If you want to remove existing body, call set_body() instead. Note that current object is no longer usable after calling this function.