Repository navigation
Expand file tree
/
Copy pathhttp2_request_engine.hpp
More file actions
75 lines (74 loc) · 3.64 KB
/
Copy pathhttp2_request_engine.hpp
File metadata and controls
75 lines (74 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
This file is part of libhttpserver
Copyright (C) 2011-2026 Sebastiano Merlino
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#if !defined(HTTPSERVER_COMPILATION)
#error "http2_request_engine.hpp is internal"
#endif
#ifndef SRC_HTTPSERVER_DETAIL_HTTP2_REQUEST_ENGINE_HPP_
#define SRC_HTTPSERVER_DETAIL_HTTP2_REQUEST_ENGINE_HPP_
#include <memory>
#include <httpserver/detail/http2_connection.hpp>
#include <httpserver/detail/request_lifecycle.hpp>
#include <httpserver/concurrency/executor.hpp>
#include <httpserver/server/routes.hpp>
#include <httpserver/server/server.hpp>
#include <httpserver/websocket/options.hpp>
namespace httpserver::detail {
class drain_scope;
struct http2_native_context {
executor* workers = nullptr;
std::shared_ptr<drain_scope> drain;
std::shared_ptr<const server::tls_peer_metadata> tls;
std::shared_ptr<executor::handler> progress;
};
struct http2_request_limits {
hpack_section_limits headers{65536, 65536, 256};
// Bounds live streams and pending output items, including reset-only items.
std::size_t max_streams = 128;
std::size_t decoder_table_bytes = 4096;
std::size_t body_buffer_bytes = 16384, response_buffer_bytes = 16384;
http2_limits connection{};
websocket::options websocket{16384, 65536, 65536, 16, 16};
server::timeout_options timeouts{};
};
// Internal streaming composition seam. The supplied executor must serialize
// handlers with all engine calls in the connection owner's execution domain.
// Routes and executor outlive the engine. Engine destruction invalidates queued
// and parked handler frames; no detached task borrows exchange storage.
// feed() consumes one frame/control event and owns its release. Non-END_STREAM
// heads dispatch immediately. Extended CONNECT maps a WebSocket to one stream.
// The public listener still dispatches HTTP/1; negotiated h2 wiring is separate.
class http2_request_engine {
public:
http2_request_engine(server::resource_budget budget, const server::route_registry& routes,
executor& owner, http2_request_limits limits = {},
request_dispatch_context dispatch = {}, std::uint64_t connection_id = 0, net::peer_address peer = {}, http2_native_context native = {});
~http2_request_engine();
static std::size_t stream_storage();
http2_request_engine(const http2_request_engine&) = delete;
http2_request_engine& operator=(const http2_request_engine&) = delete;
// Nonblocking, owner-serialized initiation. remaining counts one connection
// plus each admitted stream. The owner must pump at the absolute deadline:
// this composition seam has no transport timer. The same owner pump services
// WebSocket ws_close and write_idle deadlines while running. Waiters only request cancel.
http::outcome begin_drain(http2_connection::time_point deadline, server::drain_ticket& out);
void check_drain(http2_connection::time_point now);
void begin_turn();
std::optional<http2_connection::time_point> next_deadline(http2_connection::time_point now);
std::size_t active_streams() const;
bool draining_finished() const;
void stop(http::outcome_code reason);
http2_feed_result feed(std::span<const std::uint8_t> bytes, http2_connection::time_point now = {});
http2_feed_result eof();
std::span<const std::uint8_t> output(http2_connection::time_point now = {});
bool advance_output(std::size_t count);
const std::optional<http2_error>& failure() const;
private:
friend struct http2_native_test_access;
struct state;
std::shared_ptr<state> state_;
};
} // namespace httpserver::detail
#endif // SRC_HTTPSERVER_DETAIL_HTTP2_REQUEST_ENGINE_HPP_