userver: userver/server/request/task_inherited_request.hpp Source File
Loading...
Searching...
No Matches
task_inherited_request.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/request/task_inherited_request.hpp
4/// @brief Functions that provide access to HttpRequest stored in
5/// TaskInheritedVariable.
6
7#include <string>
8#include <string_view>
9
10#include <boost/container/small_vector.hpp>
11#include <boost/range/iterator_range.hpp>
12
13#include <userver/http/header_map.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace http::headers {
18class PredefinedHeader;
19} // namespace http::headers
20
21namespace server::request {
22
23struct Header {
24 std::string_view name;
25 std::string value;
26
27 Header(std::string_view name, std::string value)
28 : name(name),
29 value(std::move(value))
30 {}
31};
32
33using HeadersToPropagate = boost::container::small_vector<Header, 10>;
34
35/// @brief Get a header from server::http::HttpRequest that is handled by the
36/// current task hierarchy.
37/// @return Header value or an empty string, if none such
38const std::string& GetPropagatedHeader(std::string_view header_name);
39
40/// @overload
41const std::string& GetPropagatedHeader(const USERVER_NAMESPACE::http::headers::PredefinedHeader& header_name);
42
43/// @brief Checks whether specified header exists in server::http::HttpRequest
44/// that is handled by the current task hierarchy.
45/// @return `true` if the header exists, `false` otherwise
46bool HasPropagatedHeader(std::string_view header_name);
47
48/// @overload
49bool HasPropagatedHeader(const USERVER_NAMESPACE::http::headers::PredefinedHeader& header_name);
50
51/// @brief Get a headers that is handled by the current task hierarchy.
52boost::iterator_range<HeadersToPropagate::const_iterator> GetPropagatedHeaders();
53
54/// @brief Set a headers that is handled by the current task hierarchy.
55void SetPropagatedHeaders(HeadersToPropagate headers);
56
57/// @brief Get a query parameter from server::http::HttpRequest that is handled
58/// by the current task hierarchy.
59/// @return Parameter value or an empty string, if none such
60const std::string& GetTaskInheritedQueryParameter(std::string_view name);
61
62/// @brief Checks whether specified query parameter exists in
63/// server::http::HttpRequest that is handled by the current task hierarchy.
64/// @return `true` if the parameter exists, `false` otherwise
65bool HasTaskInheritedQueryParameter(std::string_view name);
66
67} // namespace server::request
68
69USERVER_NAMESPACE_END