userver: userver/clients/http/component_core.hpp Source File
Loading...
Searching...
No Matches
component_core.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef USERVER_TVM2_HTTP_CLIENT
4#error Use components::Http from clients/http.hpp instead
5#endif
6
7/// @file userver/clients/http/component_core.hpp
8/// @brief @copybrief components::HttpClientCore
9
10#include <userver/components/component_base.hpp>
11#include <userver/concurrent/async_event_source.hpp>
12#include <userver/dynamic_config/snapshot.hpp>
13#include <userver/utils/statistics/entry.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace clients::http {
18
19class ClientCore;
20
21} // namespace clients::http
22
23namespace components {
24
25// clang-format off
26
27/// @ingroup userver_components
28///
29/// @brief Component that manages @ref clients::http::ClientCore.
30///
31/// Returned references to @ref clients::http::ClientCore live for a lifetime of the
32/// component and are safe for concurrent use.
33///
34/// ## Dynamic options:
35/// * @ref HTTP_CLIENT_CONNECT_THROTTLE
36/// * @ref HTTP_CLIENT_CONNECTION_POOL_SIZE
37///
38/// ## Static options @ref components::HttpClientCore :
39/// @include{doc} scripts/docs/en/components_schema/core/src/clients/http/component_core.md
40///
41/// Options inherited from @ref components::ComponentBase :
42/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
43///
44/// ## Static configuration example:
45///
46/// @snippet components/common_component_list_test.cpp Sample http client component config
47
48// clang-format on
49class HttpClientCore final : public ComponentBase {
50public:
51 /// @ingroup userver_component_names
52 /// @brief The default name of components::HttpClientCore component
53 static constexpr std::string_view kName = "http-client-core";
54
55 HttpClientCore(const ComponentConfig&, const ComponentContext&);
56
57 ~HttpClientCore() override;
58
59 /// @cond
60 // For internal use only.
61 std::shared_ptr<clients::http::ClientCore> GetHttpClientCore(utils::impl::InternalTag);
62 /// @endcond
63
64 static yaml_config::Schema GetStaticConfigSchema();
65
66private:
67 void OnConfigUpdate(const dynamic_config::Snapshot& config);
68
69 void WriteStatistics(utils::statistics::Writer& writer);
70
71 const bool disable_pool_stats_;
72 std::shared_ptr<clients::http::ClientCore> http_client_;
73 concurrent::AsyncEventSubscriberScope subscriber_scope_;
74 utils::statistics::Entry statistics_holder_;
75};
76
77template <>
78inline constexpr bool kHasValidate<HttpClientCore> = true;
79
80template <>
81inline constexpr auto kConfigFileMode<HttpClientCore> = ConfigFileMode::kNotRequired;
82
83} // namespace components
84
85USERVER_NAMESPACE_END