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/engine/multi_consumer_event.hpp>
14#include <userver/utils/statistics/entry.hpp>
15
16USERVER_NAMESPACE_BEGIN
17
18namespace clients::http {
19
20class ClientCore;
21
22} // namespace clients::http
23
24namespace components {
25
26// clang-format off
27
28/// @ingroup userver_components
29///
30/// @brief Component that manages @ref clients::http::ClientCore.
31///
32/// Returned references to @ref clients::http::ClientCore live for a lifetime of the
33/// component and are safe for concurrent use.
34///
35/// ## Dynamic options:
36/// * @ref HTTP_CLIENT_CONNECT_THROTTLE
37/// * @ref HTTP_CLIENT_CONNECTION_POOL_SIZE
38///
39/// ## Static options @ref components::HttpClientCore :
40/// @include{doc} scripts/docs/en/components_schema/core/src/clients/http/component_core.md
41///
42/// Options inherited from @ref components::ComponentBase :
43/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
44///
45/// ## Static configuration example:
46///
47/// @snippet components/common_component_list_test.cpp Sample http client component config
48
49// clang-format on
50class HttpClientCore final : public ComponentBase {
51public:
52 /// @ingroup userver_component_names
53 /// @brief The default name of components::HttpClientCore component
54 static constexpr std::string_view kName = "http-client-core";
55
56 HttpClientCore(const ComponentConfig&, const ComponentContext&);
57
58 ~HttpClientCore() override;
59
60 /// @cond
61 // For internal use only.
62 std::shared_ptr<clients::http::ClientCore> GetHttpClientCore(utils::impl::InternalTag);
63
64 // For internal use only.
65 void WaitUntilConfigSet() const;
66 /// @endcond
67
68 static yaml_config::Schema GetStaticConfigSchema();
69
70private:
71 void OnLoadingCancelled() override;
72
73 void OnConfigUpdate(const dynamic_config::Diff& diff);
74
75 void WriteStatistics(utils::statistics::Writer& writer);
76
77 const bool disable_pool_stats_;
78 std::shared_ptr<clients::http::ClientCore> http_client_;
79
80 std::atomic<bool> is_loading_cancelled_{false};
81 mutable engine::MultiConsumerEvent config_updated_event_;
82
83 // subscriber_scope_ must be the last field.
84 concurrent::AsyncEventSubscriberScope subscriber_scope_;
85};
86
87template <>
88inline constexpr bool kHasValidate<HttpClientCore> = true;
89
90template <>
91inline constexpr auto kConfigFileMode<HttpClientCore> = ConfigFileMode::kNotRequired;
92
93} // namespace components
94
95USERVER_NAMESPACE_END