userver: userver/clients/http/component.hpp Source File
Loading...
Searching...
No Matches
component.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.hpp
8/// @brief @copybrief components::HttpClient
9
10#include <userver/clients/http/client.hpp>
11#include <userver/components/component_base.hpp>
12#include <userver/concurrent/async_event_source.hpp>
13#include <userver/dynamic_config/snapshot.hpp>
14#include <userver/utils/statistics/entry.hpp>
15
16USERVER_NAMESPACE_BEGIN
17
18namespace components {
19
20// clang-format off
21
22/// @ingroup userver_components
23///
24/// @brief Component that manages clients::http::Client.
25///
26/// Returned references to clients::http::Client live for a lifetime of the
27/// component and are safe for concurrent use.
28///
29/// ## Dynamic options:
30/// * @ref HTTP_CLIENT_CONNECT_THROTTLE
31/// * @ref HTTP_CLIENT_CONNECTION_POOL_SIZE
32/// * @ref USERVER_HTTP_PROXY
33///
34/// ## Static options:
35/// Name | Description | Default value
36/// ---- | ----------- | -------------
37/// pool-statistics-disable | set to true to disable statistics for connection pool | false
38/// thread-name-prefix | set OS thread name to this value | ''
39/// threads | number of threads to process low level HTTP related IO system calls | 8
40/// fs-task-processor | task processor to run blocking HTTP related calls, like DNS resolving or hosts reading | -
41/// destination-metrics-auto-max-size | set max number of automatically created destination metrics | 100
42/// user-agent | User-Agent HTTP header to show on all requests, result of utils::GetUserverIdentifier() if empty | empty
43/// bootstrap-http-proxy | HTTP proxy to use at service start. Will be overridden by @ref USERVER_HTTP_PROXY at runtime config update | ''
44/// testsuite-enabled | enable testsuite testing support | false
45/// testsuite-timeout | if set, force the request timeout regardless of the value passed in code | -
46/// testsuite-allowed-url-prefixes | if set, checks that all URLs start with any of the passed prefixes, asserts if not. Set for testing purposes only. | ''
47/// dns_resolver | server hostname resolver type (getaddrinfo or async) | 'async'
48/// set-deadline-propagation-header | whether to set http::common::kXYaTaxiClientTimeoutMs request header, see @ref scripts/docs/en/userver/deadline_propagation.md | true
49/// plugins | Plugin names to apply. A plugin component is called "http-client-plugin-" plus the plugin name. | []
50/// cancellation-policy | Cancellation policy for new requests. | cancel
51///
52/// ## Static configuration example:
53///
54/// @snippet components/common_component_list_test.cpp Sample http client component config
55
56// clang-format on
57class HttpClient final : public ComponentBase {
58public:
59 /// @ingroup userver_component_names
60 /// @brief The default name of components::HttpClient component
61 static constexpr std::string_view kName = "http-client";
62
63 HttpClient(const ComponentConfig&, const ComponentContext&);
64
65 ~HttpClient() override;
66
67 clients::http::Client& GetHttpClient();
68
69 static yaml_config::Schema GetStaticConfigSchema();
70
71private:
72 void OnConfigUpdate(const dynamic_config::Snapshot& config);
73
74 void WriteStatistics(utils::statistics::Writer& writer);
75
76 static std::vector<utils::NotNull<clients::http::Plugin*>>
77 FindPlugins(const std::vector<std::string>& names, const components::ComponentContext& context);
78
79 const bool disable_pool_stats_;
80 clients::http::Client http_client_;
81 concurrent::AsyncEventSubscriberScope subscriber_scope_;
82 utils::statistics::Entry statistics_holder_;
83};
84
85template <>
86inline constexpr bool kHasValidate<HttpClient> = true;
87
88} // namespace components
89
90USERVER_NAMESPACE_END