33#include <seastar/core/iostream.hh>
34#include <seastar/core/sstring.hh>
36#include <seastar/http/common.hh>
37#include <seastar/http/mime_types.hh>
38#include <seastar/net/socket_defs.hh>
39#include <seastar/core/iostream.hh>
40#include <seastar/util/string_utils.hh>
41#include <seastar/util/iostream.hh>
47namespace experimental {
class connection; }
55 other, multipart, app_x_www_urlencoded,
63 ctclass content_type_class;
64 size_t content_length = 0;
65 mutable size_t _bytes_written = 0;
66 std::unordered_map<sstring, sstring, seastar::internal::case_insensitive_hash, seastar::internal::case_insensitive_cmp> _headers;
67 std::unordered_map<sstring, sstring> query_parameters;
76 std::unordered_map<sstring, sstring> trailing_headers;
77 std::unordered_map<sstring, sstring> chunk_extensions;
78 sstring protocol_name =
"http";
86 return _client_address;
94 return _server_address;
103 auto res = _headers.find(name);
104 if (res == _headers.end()) {
116 auto res = query_parameters.find(key);
117 if (res == query_parameters.end()) {
130 return param.get_decoded_param(key);
137 return protocol_name;
148 bool is_multi_part()
const {
149 return content_type_class == ctclass::multipart;
152 bool is_form_post()
const {
153 return content_type_class == ctclass::app_x_www_urlencoded;
156 bool should_keep_alive()
const {
157 if (_version ==
"0.9") {
163 auto it = _headers.find(
"Connection");
164 if (_version ==
"1.0") {
165 return it != _headers.end()
166 && seastar::internal::case_insensitive_cmp()(it->second,
"keep-alive");
168 return it == _headers.end() || !seastar::internal::case_insensitive_cmp()(it->second,
"close");
192 _headers[
"Content-Type"] = mime;
200 set_mime_type(http::mime_types::extension_to_type(content_type));
214 void write_body(
const sstring& content_type, sstring content);
241 template <
typename W>
243 void write_body(
const sstring& content_type, W&& body_writer) {
245 return util::write_to_stream_and_close(std::move(out), std::move(body_writer));
279 template <
typename W>
281 void write_body(
const sstring& content_type,
size_t len, W&& body_writer) {
283 return util::write_to_stream_and_close(std::move(out), std::move(body_writer));
314 static request make(httpd::operation_type type, sstring host, sstring path);
317 void add_query_param(std::string_view param);
318 sstring request_line()
const;
326using request [[deprecated(
"Use http::request instead")]] =
http::request;
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Class connection represents an HTTP connection over a given transport.
Definition: client.hh:68
Definition: socket_defs.hh:47
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: noncopyable_function.hh:37
Definition: request.hh:52
sstring format_url() const
sstring parse_query_param()
sstring get_path_param(const sstring &key) const
Definition: request.hh:129
sstring get_header(const sstring &name) const
Definition: request.hh:102
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.
void set_mime_type(const sstring &mime)
Definition: request.hh:191
void write_body(const sstring &content_type, W &&body_writer)
use and output stream to write the message body
Definition: request.hh:243
void write_body(const sstring &content_type, size_t len, W &&body_writer)
use and output stream to write the message body
Definition: request.hh:281
const socket_address & get_client_address() const
Definition: request.hh:85
void set_content_type(const sstring &content_type="html")
Definition: request.hh:199
void write_body(const sstring &content_type, sstring content)
Write a string as the body.
static request make(sstring method, sstring host, sstring path)
Make simple request.
void set_expects_continue()
Make request send Expect header.
static request make(httpd::operation_type type, sstring host, sstring path)
Make simple request.
void write_body(const sstring &content_type, noncopyable_function< future<>(output_stream< char > &&)> &&body_writer)
Use an output stream to write the message body.
sstring get_url() const
Definition: request.hh:144
const socket_address & get_server_address() const
Definition: request.hh:93
sstring get_query_param(const sstring &key) const
Definition: request.hh:115
sstring get_protocol_name() const
Definition: request.hh:136