28#include <boost/intrusive/list.hpp>
30#include <seastar/http/request_parser.hh>
31#include <seastar/http/request.hh>
32#include <seastar/core/seastar.hh>
33#include <seastar/core/sstring.hh>
34#include <seastar/core/app-template.hh>
35#include <seastar/core/circular_buffer.hh>
36#include <seastar/core/distributed.hh>
37#include <seastar/core/queue.hh>
38#include <seastar/core/gate.hh>
40#include <seastar/util/std-compat.hh>
41#include <seastar/util/modules.hh>
42#include <seastar/http/routes.hh>
43#include <seastar/net/tls.hh>
44#include <seastar/core/shared_ptr.hh>
60using namespace std::chrono_literals;
62SEASTAR_MODULE_EXPORT_BEGIN
69class connection :
public boost::intrusive::list_base_hook<> {
76 static constexpr size_t limit = 4096;
78 http_request_parser _parser;
79 std::unique_ptr<http::request> _req;
80 std::unique_ptr<http::reply> _resp;
86 [[deprecated(
"use connection(http_server&, connected_socket&&, bool tls)")]]
92 , _read_buf(_fd.
input())
103 , _read_buf(_fd.
input())
104 , _write_buf(_fd.
output())
105 , _client_addr(std::move(client_addr))
106 , _server_addr(std::move(server_addr))
111 void on_new_connection();
124 future<bool> generate_reply(std::unique_ptr<http::request> req);
125 void generate_error_reply_and_close(std::unique_ptr<http::request> req,
http::reply::status_type status,
const sstring& msg);
135 std::vector<server_socket> _listeners;
137 uint64_t _total_connections = 0;
138 uint64_t _current_connections = 0;
139 uint64_t _requests_served = 0;
140 uint64_t _read_errors = 0;
141 uint64_t _respond_errors = 0;
143 sstring _date = http_date();
144 timer<> _date_format_timer { [
this] {_date = http_date();} };
145 size_t _content_length_limit = std::numeric_limits<size_t>::max();
146 bool _content_streaming =
false;
152 explicit http_server(
const sstring& name) : _stats(*
this, name) {
181 [[deprecated(
"use listen(socket_address addr, server_credentials_ptr credentials)")]]
184 size_t get_content_length_limit()
const;
186 void set_content_length_limit(
size_t limit);
188 bool get_content_streaming()
const;
190 void set_content_streaming(
bool b);
199 future<> do_accepts(
int which,
bool with_tls);
201 uint64_t total_connections()
const;
202 uint64_t current_connections()
const;
203 uint64_t requests_served()
const;
204 uint64_t read_errors()
const;
205 uint64_t reply_errors()
const;
208 static sstring http_date();
210 future<> do_accept_one(
int which,
bool with_tls);
211 boost::intrusive::list<connection> _connections;
218 static std::vector<server_socket>& listeners(
http_server& server) {
219 return server._listeners;
237 std::unique_ptr<distributed<http_server>> _server_dist;
239 static sstring generate_server_name();
244 future<> start(
const sstring& name = generate_server_name());
253SEASTAR_MODULE_EXPORT_END
output_stream< char > output(size_t buffer_size=8192)
input_stream< char > input(connected_socket_input_stream_config csisc={})
socket_address local_address() const noexcept
Local address of the socket.
socket_address remote_address() const noexcept
Remote address of the socket.
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
void set_tls_credentials(server_credentials_ptr credentials)
set tls credentials for the server Setting the tls credentials will set the http-server to work in ht...
holds the metric definition.
Definition: metrics_registration.hh:94
Definition: sharded.hh:182
Definition: socket_defs.hh:47
void arm_periodic(duration delta) noexcept
Definition: timer.hh:188
server_socket listen(socket_address sa)
holds the metric_groups definition needed by class that reports metrics
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
status_type
Definition: reply.hh:65