userver: userver/server/server.hpp Source File
Loading...
Searching...
No Matches
server.hpp
1#pragma once
2
3#include <userver/formats/json/value.hpp>
4
5#include <userver/components/component_context.hpp>
6#include <userver/engine/task/task_processor_fwd.hpp>
7#include <userver/server/congestion_control/limiter.hpp>
8#include <userver/server/congestion_control/sensor.hpp>
9#include <userver/server/handlers/fallback_handlers.hpp>
10#include <userver/server/handlers/http_handler_base.hpp>
11#include <userver/storages/secdist/component.hpp>
12#include <userver/utils/statistics/fwd.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace server {
17
18namespace net {
19struct StatsAggregation;
20}
21
22namespace http {
23class HttpRequestHandler;
24}
25
26class RequestsView;
27
28class ServerImpl;
29struct ServerConfig;
30
31class Server final : public congestion_control::Limitee, public congestion_control::RequestsSource {
32public:
33 Server(
34 ServerConfig config,
35 const storages::secdist::SecdistConfig& secdist,
36 const components::ComponentContext& component_context
37 );
38 ~Server() override;
39
40 const ServerConfig& GetConfig() const;
41
42 std::vector<std::string> GetCommonMiddlewares() const;
43
44 void WriteMonitorData(utils::statistics::Writer& writer) const;
45
46 void WriteTotalHandlerStatistics(utils::statistics::Writer& writer) const;
47
48 net::StatsAggregation GetServerStats() const;
49
50 void AddHandler(const handlers::HttpHandlerBase& handler, engine::TaskProcessor& task_processor);
51
52 size_t GetThrottlableHandlersCount() const;
53
54 const http::HttpRequestHandler& GetHttpRequestHandler(bool is_monitor = false) const;
55
56 void Start();
57
58 void Stop();
59
60 RequestsView& GetRequestsView();
61
62 void SetLimit(std::optional<size_t> new_limit) override;
63
64 void SetRpsRatelimit(std::optional<size_t> rps);
65
66 void SetRpsRatelimitStatusCode(http::HttpStatus status_code);
67
68 std::uint64_t GetTotalRequests() const override;
69
70private:
71 std::unique_ptr<ServerImpl> pimpl;
72};
73
74} // namespace server
75
76USERVER_NAMESPACE_END