userver: userver/server/handlers/ping.hpp Source File
Loading...
Searching...
No Matches
ping.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/ping.hpp
4/// @brief @copybrief server::handlers::Ping
5
6#include <userver/components/state.hpp>
7#include <userver/server/handlers/http_handler_base.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace server::handlers {
12
13/// @ingroup userver_components userver_http_handlers
14///
15/// @brief Handler that returns HTTP 200 if the service is OK and able to
16/// process requests.
17///
18/// Uses components::State::IsAnyComponentInFatalState() to detect
19/// fatal state (can not process requests).
20///
21/// ## Static options:
22/// Inherits all the options from server::handlers::HttpHandlerBase
23/// @ref userver_http_handlers
24/// and adds the following ones:
25///
26/// Name | Description | Default value
27/// ---- | ----------- | -------------
28/// warmup-time-secs | how much time it needs to warmup the server | 0
29class Ping final : public HttpHandlerBase {
30public:
31 Ping(const components::ComponentConfig& config, const components::ComponentContext& component_context);
32
33 /// @ingroup userver_component_names
34 /// @brief The default name of server::handlers::Ping
35 static constexpr std::string_view kName = "handler-ping";
36
37 std::string HandleRequestThrow(const http::HttpRequest& request, request::RequestContext& context) const override;
38
39 void OnAllComponentsLoaded() override;
40
41 static yaml_config::Schema GetStaticConfigSchema();
42
43private:
44 void AppendWeightHeaders(http::HttpResponse&) const;
45
46 const components::State components_;
47
48 std::chrono::steady_clock::time_point load_time_{};
49 std::chrono::seconds awacs_weight_warmup_time_{60};
50};
51
52} // namespace server::handlers
53
54template <>
55inline constexpr bool components::kHasValidate<server::handlers::Ping> = true;
56
57USERVER_NAMESPACE_END