Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
seastar::http::reply Struct Reference

Detailed Description

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 , page_expired = 419 ,
  unprocessable_entity = 422 , upgrade_required = 426 , too_many_requests = 429 , login_timeout = 440 ,
  internal_server_error = 500 , not_implemented = 501 , bad_gateway = 502 , service_unavailable = 503 ,
  gateway_timeout = 504 , http_version_not_supported = 505 , insufficient_storage = 507 , bandwidth_limit_exceeded = 509 ,
  network_read_timeout = 598 , network_connect_timeout = 599
}
 
enum class  status_class : uint8_t {
  informational = 1 , success = 2 , redirection = 3 , client_error = 4 ,
  server_error = 5 , unclassified
}
 

Public Member Functions

replyadd_header (const sstring &h, const sstring &value)
 
sstring get_header (const sstring &name) const
 
replyset_version (const sstring &version)
 
replyset_status (status_type status, sstring content="")
 
replyset_mime_type (const sstring &mime)
 
replyset_content_type (const sstring &content_type="html")
 
replydone (const sstring &content_type)
 
replydone ()
 
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
 

Member Enumeration Documentation

◆ status_class

enum class seastar::http::reply::status_class : uint8_t
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

◆ status_type

The status of the reply.

Enumerator
continue_ 

continue

switching_protocols 

switching_protocols

ok 

ok

created 

created

accepted 

accepted

nonauthoritative_information 

nonauthoritative_information

no_content 

no_content

reset_content 

reset_content

multiple_choices 

partial_content

multiple_choices

moved_permanently 

moved_permanently

moved_temporarily 

moved_temporarily

see_other 

see_other

not_modified 

not_modified

use_proxy 

use_proxy

temporary_redirect 

temporary_redirect

bad_request 

bad_request

unauthorized 

unauthorized

payment_required 

payment_required

forbidden 

forbidden

not_found 

not_found

method_not_allowed 

method_not_allowed

not_acceptable 

not_acceptable

request_timeout 

request_timeout

conflict 

conflict

gone 

gone

length_required 

length_required

payload_too_large 

payload_too_large

uri_too_long 

uri_too_long

unsupported_media_type 

unsupported_media_type

expectation_failed 

expectation_failed

page_expired 

page_expired

unprocessable_entity 

unprocessable_entity

upgrade_required 

upgrade_required

too_many_requests 

too_many_requests

login_timeout 

login_timeout

internal_server_error 

internal_server_error

not_implemented 

not_implemented

bad_gateway 

bad_gateway

service_unavailable 

service_unavailable

gateway_timeout 

gateway_timeout

http_version_not_supported 

http_version_not_supported

insufficient_storage 

insufficient_storage

bandwidth_limit_exceeded 

bandwidth_limit_exceeded

network_read_timeout 

network_read_timeout

network_connect_timeout 

network_connect_timeout

Member Function Documentation

◆ classify_status()

static constexpr status_class seastar::http::reply::classify_status ( status_type  http_status)
inlinestaticconstexpr

Classify http status

Parameters
http_statusthe http status status_type
Returns
one of the status_class values

◆ done()

reply & seastar::http::reply::done ( )
inline

Done should be called before using the reply. It would set the response line

◆ get_header()

sstring seastar::http::reply::get_header ( const sstring &  name) const
inline

Search for the first header of a given name

Parameters
namethe header name
Returns
a pointer to the header value, if it exists or empty string

◆ set_content_type()

reply & seastar::http::reply::set_content_type ( const sstring &  content_type = "html")
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'

◆ set_mime_type()

reply & seastar::http::reply::set_mime_type ( const sstring &  mime)
inline

Set the content type mime type. Used when the mime type is known. For most cases, use the set_content_type

◆ write_body() [1/3]

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.

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

◆ write_body() [2/3]

void seastar::http::reply::write_body ( const sstring &  content_type,
sstring  content 
)

Write a string as the reply.

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

◆ write_body() [3/3]

template<typename W >
requires std::is_invocable_r_v<future<>, W, output_stream<char>&>
void seastar::http::reply::write_body ( const sstring &  content_type,
W &&  body_writer 
)
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

Member Data Documentation

◆ _content

sstring seastar::http::reply::_content

The content to be sent in the reply.

◆ _headers

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.


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