A request received from a client.
#include <seastar/http/request.hh>
|
enum class | ctclass : char { other
, multipart
, app_x_www_urlencoded
} |
|
|
const socket_address & | get_client_address () const |
|
const socket_address & | get_server_address () const |
|
sstring | get_header (const sstring &name) const |
|
sstring | get_query_param (const sstring &key) const |
|
sstring | get_path_param (const sstring &key) const |
|
sstring | get_protocol_name () const |
|
sstring | get_url () const |
|
bool | is_multi_part () const |
|
bool | is_form_post () const |
|
bool | should_keep_alive () const |
|
sstring | parse_query_param () |
|
sstring | format_url () const |
|
void | set_mime_type (const sstring &mime) |
|
void | set_content_type (const sstring &content_type="html") |
|
void | write_body (const sstring &content_type, sstring content) |
| Write a string as the body. More...
|
|
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, size_t len, 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, size_t len, W &&body_writer) |
| use and output stream to write the message body More...
|
|
void | set_expects_continue () |
| Make request send Expect header. More...
|
|
|
static request | make (sstring method, sstring host, sstring path) |
| Make simple request. More...
|
|
static request | make (httpd::operation_type type, sstring host, sstring path) |
| Make simple request. More...
|
|
|
socket_address | _client_address |
|
socket_address | _server_address |
|
sstring | _method |
|
sstring | _url |
|
sstring | _version |
|
ctclass | content_type_class |
|
size_t | content_length = 0 |
|
size_t | _bytes_written = 0 |
|
std::unordered_map< sstring, sstring, seastar::internal::case_insensitive_hash, seastar::internal::case_insensitive_cmp > | _headers |
|
std::unordered_map< sstring, sstring > | query_parameters |
|
httpd::parameters | param |
|
sstring | content |
|
input_stream< char > * | content_stream |
|
std::unordered_map< sstring, sstring > | trailing_headers |
|
std::unordered_map< sstring, sstring > | chunk_extensions |
|
sstring | protocol_name = "http" |
|
noncopyable_function< future<>(output_stream< char > &&)> | body_writer |
|
◆ format_url()
sstring seastar::http::request::format_url |
( |
| ) |
const |
Generates the URL string from the _url and query_parameters values in a form parseable by the above method
◆ get_client_address()
const socket_address & seastar::http::request::get_client_address |
( |
| ) |
const |
|
inline |
Get the address of the client that generated the request
- Returns
- The address of the client that generated the request
◆ get_header()
sstring seastar::http::request::get_header |
( |
const sstring & |
name | ) |
const |
|
inline |
Search for the first header of a given name
- Parameters
-
- Returns
- a pointer to the header value, if it exists or empty string
◆ get_path_param()
sstring seastar::http::request::get_path_param |
( |
const sstring & |
key | ) |
const |
|
inline |
Search for the last path parameter of a given key
- Parameters
-
key | the path paramerter key |
- Returns
- the unescaped path parameter value, if it exists and can be path decoded successfully, otherwise it returns an empty string
◆ get_protocol_name()
sstring seastar::http::request::get_protocol_name |
( |
| ) |
const |
|
inline |
Get the request protocol name. Can be either "http" or "https".
◆ get_query_param()
sstring seastar::http::request::get_query_param |
( |
const sstring & |
key | ) |
const |
|
inline |
Search for the last query parameter of a given key
- Parameters
-
key | the query paramerter key |
- Returns
- the query parameter value, if it exists or empty string
◆ get_server_address()
const socket_address & seastar::http::request::get_server_address |
( |
| ) |
const |
|
inline |
Get the address of the server that handled the request
- Returns
- The address of the server that handled the request
◆ get_url()
sstring seastar::http::request::get_url |
( |
| ) |
const |
|
inline |
Get the request url.
- Returns
- the request url
◆ make() [1/2]
static request seastar::http::request::make |
( |
httpd::operation_type |
type, |
|
|
sstring |
host, |
|
|
sstring |
path |
|
) |
| |
|
static |
Make simple request.
- Parameters
-
method | - method to use, e.g. operation_type::GET |
host | - host to contact. This value will be used as the "Host" header \path - the URL to send the request to |
◆ make() [2/2]
static request seastar::http::request::make |
( |
sstring |
method, |
|
|
sstring |
host, |
|
|
sstring |
path |
|
) |
| |
|
static |
Make simple request.
- Parameters
-
method | - method to use, e.g. "GET" or "POST" |
host | - host to contact. This value will be used as the "Host" header \path - the URL to send the request to |
◆ parse_query_param()
sstring seastar::http::request::parse_query_param |
( |
| ) |
|
Set the query parameters in the request objects. Returns the URL path part, i.e. – without the query paremters query param appear after the question mark and are separated by the ampersand sign
◆ set_content_type()
void seastar::http::request::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_expects_continue()
void seastar::http::request::set_expects_continue |
( |
| ) |
|
Make request send Expect header.
When set, the connection::make_request will send the Expect header and will wait for the server resply before tranferring the body
◆ set_mime_type()
void seastar::http::request::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/5]
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. |
This method can be used to write body of unknown or hard to evaluate length. For example, when sending the contents of some other input_stream or when the body is available as a collection of memory buffers. Message would use chunked transfer encoding.
◆ write_body() [2/5]
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') |
len | - known in advance content length |
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. |
This method is to be used when the body is not available of a single contiguous buffer, but the size of it is known and it's desirable to provide it to the server, or when the server strongly requires the content-length header for any reason.
Message would use plain encoding in the the reply with Content-Length header set accordingly. If the body_writer doesn't generate enough bytes into the stream or tries to put more data into the stream, sending the request would resolve with exceptional future.
◆ write_body() [3/5]
void seastar::http::request::write_body |
( |
const sstring & |
content_type, |
|
|
size_t |
len, |
|
|
W && |
body_writer |
|
) |
| |
|
inline |
use and output stream to write the message body
The same as above, but the caller can only .write() data into the stream, it will be closed (and flushed) automatically after the writer fn resolves
◆ write_body() [4/5]
void seastar::http::request::write_body |
( |
const sstring & |
content_type, |
|
|
sstring |
content |
|
) |
| |
Write a string as the body.
- 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, conent length and content type of the message along with any additional information that is needed to send the message. |
This method is good to be used if the body is available as a contiguous buffer.
◆ write_body() [5/5]
void seastar::http::request::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 caller can only .write() data into the stream, it will be closed (and flushed) automatically after the writer fn resolves
The documentation for this struct was generated from the following file: