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/server/handlers/http_handler_base.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace server::handlers {
11
12/// @ingroup userver_components userver_http_handlers
13///
14/// @brief Handler that returns HTTP 200 if the service is OK and able to
15/// process requests.
16///
17/// Uses components::ComponentContext::IsAnyComponentInFatalState() to detect
18/// fatal state (can not process requests).
19///
20/// ## Static options:
21/// Inherits all the options from server::handlers::HttpHandlerBase
22/// @ref userver_http_handlers
23/// and adds the following ones:
24///
25/// Name | Description | Default value
26/// ---- | ----------- | -------------
27/// warmup-time-secs | how much time it needs to warmup the server | 0
28///
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::ComponentContext& 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