Seastar
High performance C++ framework for concurrent servers
Public Types | 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 , 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

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 ()
 
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
 

Member Enumeration Documentation

◆ 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

unprocessable_entity 

unprocessable_entity

upgrade_required 

upgrade_required

too_many_requests 

too_many_requests

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

Member Function Documentation

◆ 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/2]

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/2]

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.

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: