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