userver: userver/server/middlewares/headers_propagator.hpp Source File
Loading...
Searching...
No Matches
headers_propagator.hpp
1#pragma once
2
3#include <userver/server/middlewares/http_middleware_base.hpp>
4
5USERVER_NAMESPACE_BEGIN
6
7namespace server::middlewares {
8
9class HeadersPropagator final : public HttpMiddlewareBase {
10public:
11 explicit HeadersPropagator(const handlers::HttpHandlerBase&, std::vector<std::string> headers);
12
13private:
14 void HandleRequest(http::HttpRequest& request, request::RequestContext& context) const override;
15
16 std::vector<std::string> headers_;
17};
18
19class HeadersPropagatorFactory final : public HttpMiddlewareFactoryBase {
20public:
21 static constexpr std::string_view kName = "headers-propagator";
22
23 HeadersPropagatorFactory(const components::ComponentConfig&, const components::ComponentContext&);
24
25 static yaml_config::Schema GetStaticConfigSchema();
26
27private:
28 std::unique_ptr<HttpMiddlewareBase>
29 Create(const handlers::HttpHandlerBase&, yaml_config::YamlConfig middleware_config) const override;
30
31 std::vector<std::string> headers_;
32};
33
34} // namespace server::middlewares
35
36template <>
37inline constexpr bool components::kHasValidate<server::middlewares::HeadersPropagatorFactory> = true;
38
39template <>
40inline constexpr auto components::kConfigFileMode<server::middlewares::HeadersPropagatorFactory> =
42
43USERVER_NAMESPACE_END