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///
33/// ## Static options:
34/// Name | Description | Default value
35/// ---- | ----------- | -------------
36/// pool-statistics-disable | set to true to disable statistics for connection pool | false
37/// thread-name-prefix | set OS thread name to this value | ''
38/// threads | number of threads to process low level HTTP related IO system calls | 8
39/// fs-task-processor | task processor to run blocking HTTP related calls, like DNS resolving or hosts reading | engine::current_task::GetBlockingTaskProcessor()
40/// destination-metrics-auto-max-size | set max number of automatically created destination metrics | 100
41/// user-agent | User-Agent HTTP header to show on all requests, result of utils::GetUserverIdentifier() if empty | empty
42/// testsuite-enabled | enable testsuite testing support | false
43/// testsuite-timeout | if set, force the request timeout regardless of the value passed in code | -
44/// 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. | ''
45/// dns_resolver | server hostname resolver type (getaddrinfo or async) | 'async'
46/// set-deadline-propagation-header | whether to set http::common::kXYaTaxiClientTimeoutMs request header, see @ref scripts/docs/en/userver/deadline_propagation.md | true
47/// plugins | map of plugins to apply, plugin-name -> ordering index. A plugin component is called "http-client-plugin-" plus the plugin name. | {}
48/// cancellation-policy | Cancellation policy for new requests. | cancel
49///
50/// ## Static configuration example:
51///
52/// @snippet components/common_component_list_test.cpp Sample http client component config
53
54// clang-format on
55class HttpClient final : public ComponentBase {
56public:
57 /// @ingroup userver_component_names
58 /// @brief The default name of components::HttpClient component
59 static constexpr std::string_view kName = "http-client";
60
61 HttpClient(const ComponentConfig&, const ComponentContext&);
62
63 ~HttpClient() override;
64
65 clients::http::Client& GetHttpClient();
66
67 static yaml_config::Schema GetStaticConfigSchema();
68
69private:
70 void OnConfigUpdate(const dynamic_config::Snapshot& config);
71
72 void WriteStatistics(utils::statistics::Writer& writer);
73
74 const bool disable_pool_stats_;
75 clients::http::Client http_client_;
76 concurrent::AsyncEventSubscriberScope subscriber_scope_;
77 utils::statistics::Entry statistics_holder_;
78};
79
80template <>
81inline constexpr bool kHasValidate<HttpClient> = true;
82
83template <>
84inline constexpr auto kConfigFileMode<HttpClient> = ConfigFileMode::kNotRequired;
85
86} // namespace components
87
88USERVER_NAMESPACE_END