userver: userver/server/handlers/ping.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 {
30 public:
31 Ping(const components::ComponentConfig& config,
32 const components::ComponentContext& component_context);
33
34 /// @ingroup userver_component_names
35 /// @brief The default name of server::handlers::Ping
36 static constexpr std::string_view kName = "handler-ping";
37
38 std::string HandleRequestThrow(
39 const http::HttpRequest& request,
40 request::RequestContext& context) const override;
41
42 void OnAllComponentsLoaded() override;
43
44 static yaml_config::Schema GetStaticConfigSchema();
45
46 private:
47 void AppendWeightHeaders(http::HttpResponse&) const;
48
49 const components::State components_;
50
51 std::chrono::steady_clock::time_point load_time_{};
52 std::chrono::seconds awacs_weight_warmup_time_{60};
53};
54
55} // namespace server::handlers
56
57template <>
58inline constexpr bool components::kHasValidate<server::handlers::Ping> = true;
59
60USERVER_NAMESPACE_END