Seastar
High performance C++ framework for concurrent servers
|
A reply to be sent to a client.
#include <seastar/http/reply.hh>
Public Member Functions | |
reply & | add_header (const sstring &h, const sstring &value) |
sstring | get_header (const sstring &name) const |
reply & | set_version (const sstring &version) |
reply & | set_status (status_type status, sstring content="") |
reply & | set_mime_type (const sstring &mime) |
reply & | set_content_type (const sstring &content_type="html") |
reply & | done (const sstring &content_type) |
reply & | done () |
sstring | response_line () const |
void | write_body (const sstring &content_type, noncopyable_function< future<>(output_stream< char > &&)> &&body_writer) |
use an output stream to write the message body More... | |
template<typename W > requires std::is_invocable_r_v<future<>, W, output_stream<char>&> | |
void | write_body (const sstring &content_type, W &&body_writer) |
use and output stream to write the message body More... | |
void | write_body (const sstring &content_type, sstring content) |
Write a string as the reply. More... | |
Static Public Member Functions | |
static constexpr status_class | classify_status (status_type http_status) |
Public Attributes | |
enum seastar::http::reply::status_type | _status |
std::unordered_map< sstring, sstring, seastar::internal::case_insensitive_hash, seastar::internal::case_insensitive_cmp > | _headers |
sstring | _version |
sstring | _content |
size_t | content_length = 0 |
sstring | _response_line |
std::unordered_map< sstring, sstring > | trailing_headers |
std::unordered_map< sstring, sstring > | chunk_extensions |
|
strong |
HTTP status classes See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
1xx: Informational - Request received, continuing process 2xx: Success - The action was successfully received, understood, and accepted 3xx: Redirection - Further action must be taken in order to complete the request 4xx: Client Error - The request contains bad syntax or cannot be fulfilled 5xx: Server Error - The server failed to fulfill an apparently valid request
|
strong |
The status of the reply.
|
inlinestaticconstexpr |
Classify http status
http_status | the http status status_type |
|
inline |
Done should be called before using the reply. It would set the response line
|
inline |
Search for the first header of a given name
name | the header name |
|
inline |
Set the content type mime type according to the file extension that would have been used if it was a file: e.g. html, txt, json etc'
|
inline |
Set the content type mime type. Used when the mime type is known. For most cases, use the set_content_type
void seastar::http::reply::write_body | ( | const sstring & | content_type, |
noncopyable_function< future<>(output_stream< char > &&)> && | body_writer | ||
) |
use an output stream to write the message body
When a handler needs to use an output stream it should call this method with a function.
content_type | - is used to choose the content type of the body. Use the file extension you would have used for such a content, (i.e. "txt", "html", "json", etc') |
body_writer | - a function that accept an output stream and use that stream to write the body. The function should take ownership of the stream while using it and must close the stream when it is done. |
Message would use chunked transfer encoding in the reply.
void seastar::http::reply::write_body | ( | const sstring & | content_type, |
sstring | content | ||
) |
Write a string as the reply.
content_type | - is used to choose the content type of the body. Use the file extension you would have used for such a content, (i.e. "txt", "html", "json", etc') |
content | - the message content. This would set the the content and content type of the message along with any additional information that is needed to send the message. |
|
inline |
use and output stream to write the message body
The same as above, but the handler can only .write() data into the stream, it will be closed (and flushed) automatically after the writer fn resolves
sstring seastar::http::reply::_content |
The content to be sent in the reply.
std::unordered_map<sstring, sstring, seastar::internal::case_insensitive_hash, seastar::internal::case_insensitive_cmp> seastar::http::reply::_headers |
The headers to be included in the reply.