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,
32 public congestion_control::RequestsSource {
33 public:
34 Server(ServerConfig config, const storages::secdist::SecdistConfig& secdist,
35 const components::ComponentContext& component_context);
36 ~Server() override;
37
38 const ServerConfig& GetConfig() const;
39
40 std::vector<std::string> GetCommonMiddlewares() const;
41
42 void WriteMonitorData(utils::statistics::Writer& writer) const;
43
44 void WriteTotalHandlerStatistics(utils::statistics::Writer& writer) const;
45
46 net::StatsAggregation GetServerStats() const;
47
48 void AddHandler(const handlers::HttpHandlerBase& handler,
49 engine::TaskProcessor& task_processor);
50
51 size_t GetThrottlableHandlersCount() const;
52
53 const http::HttpRequestHandler& GetHttpRequestHandler(
54 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
70 private:
71 std::unique_ptr<ServerImpl> pimpl;
72};
73
74} // namespace server
75
76USERVER_NAMESPACE_END