Seastar
High performance C++ framework for concurrent servers
|
A reply to be sent to a client.
#include <seastar/http/reply.hh>
Public Types | |
enum class | status_type { continue_ = 100 , switching_protocols = 101 , ok = 200 , created = 201 , accepted = 202 , nonauthoritative_information = 203 , no_content = 204 , reset_content = 205 , partial_content = 206 , multiple_choices = 300 , moved_permanently = 301 , moved_temporarily = 302 , see_other = 303 , not_modified = 304 , use_proxy = 305 , temporary_redirect = 307 , bad_request = 400 , unauthorized = 401 , payment_required = 402 , forbidden = 403 , not_found = 404 , method_not_allowed = 405 , not_acceptable = 406 , request_timeout = 408 , conflict = 409 , gone = 410 , length_required = 411 , payload_too_large = 413 , uri_too_long = 414 , unsupported_media_type = 415 , expectation_failed = 417 , unprocessable_entity = 422 , upgrade_required = 426 , too_many_requests = 429 , internal_server_error = 500 , not_implemented = 501 , bad_gateway = 502 , service_unavailable = 503 , gateway_timeout = 504 , http_version_not_supported = 505 , insufficient_storage = 507 } |
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 () |
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... | |
void | write_body (const sstring &content_type, sstring content) |
Write a string as the reply. More... | |
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 |
The status of the reply.
|
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. |
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.