userver: server::request Namespace Reference
Loading...
Searching...
No Matches
server::request Namespace Reference

Detailed Description

Server request related types and functions.

Classes

class  ClientMetricsShardScope
 Sets the client metrics shard (see SetClientMetricsShard) within its scope and restores the previous one on destruction. More...
class  DeadlinePropagationBlocker
 Stops deadline propagation within its scope. More...
class  DeadlineSignal
 Signals when an operation has detected deadline expiration. More...
struct  Header
struct  HttpRequestConfig
 HTTP request parsing and handling limits. More...
class  RequestContext
 Stores request-specific data during request processing. More...
struct  StorageContext
 AnyStorage tag for HTTP request context. More...
struct  TaskInheritedData
 Per-request data that should be available inside handlers. More...

Typedefs

using HeadersToPropagate = boost::container::small_vector<Header, 10>

Functions

void SetClientMetricsShard (std::string_view path, utils::statistics::LabelsSpan labels)
 Set the client metrics shard (path + labels) for requests performed by the current task and its child tasks.
void EraseClientMetricsShard () noexcept
 Remove the client metrics shard set by SetClientMetricsShard for requests performed by the current task and its child tasks.
const formats::json::Value * GetRequestJson (const RequestContext &context)
formats::json::Value & SetRequestJson (RequestContext &context, formats::json::Value request_json)
 Saves a parsed json request to the context.
const formats::json::Value * GetResponseJson (const RequestContext &context)
formats::json::Value & SetResponseJson (RequestContext &context, formats::json::Value request_json)
 Saves a json response to the context.
HttpRequestConfig Parse (const yaml_config::YamlConfig &value, formats::parse::To< HttpRequestConfig >)
engine::Deadline GetTaskInheritedDeadline () noexcept
 Returns TaskInheritedData::deadline, or an unreachable engine::Deadline if none was set.
std::optional< TaskInheritedOriginalDeadline > GetTaskInheritedOriginalDeadline () noexcept
 Returns TaskInheritedData::original_deadline, or std::nullopt if the header was absent or invalid.
void MarkTaskInheritedDeadlineExpired () noexcept
 Marks that the current TaskInheritedData::deadline has expired.
const std::string & GetPropagatedHeader (std::string_view header_name)
 Get a header from server::http::HttpRequest that is handled by the current task hierarchy.
const std::string & GetPropagatedHeader (const ::http::headers::PredefinedHeader &header_name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool HasPropagatedHeader (std::string_view header_name)
 Checks whether specified header exists in server::http::HttpRequest that is handled by the current task hierarchy.
bool HasPropagatedHeader (const ::http::headers::PredefinedHeader &header_name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::ranges::subrange< HeadersToPropagate::const_iterator > GetPropagatedHeaders ()
 Get a headers that is handled by the current task hierarchy.
void SetPropagatedHeaders (HeadersToPropagate headers)
 Set a headers that is handled by the current task hierarchy.
const std::string & GetTaskInheritedQueryParameter (std::string_view name)
 Get a query parameter from server::http::HttpRequest that is handled by the current task hierarchy.
bool HasTaskInheritedQueryParameter (std::string_view name)
 Checks whether specified query parameter exists in server::http::HttpRequest that is handled by the current task hierarchy.

Variables

engine::TaskInheritedVariable< TaskInheritedData > kTaskInheritedData

Typedef Documentation

◆ HeadersToPropagate

using server::request::HeadersToPropagate = boost::container::small_vector<Header, 10>

Definition at line 33 of file task_inherited_request.hpp.

Function Documentation

◆ GetPropagatedHeader()

const std::string & server::request::GetPropagatedHeader ( std::string_view header_name)

Get a header from server::http::HttpRequest that is handled by the current task hierarchy.

Returns
Header value or an empty string, if none such

◆ GetRequestJson()

const formats::json::Value * server::request::GetRequestJson ( const RequestContext & context)
Returns
A pointer to json request if it was parsed successfully and stored in the context or nullptr otherwise.

◆ GetResponseJson()

const formats::json::Value * server::request::GetResponseJson ( const RequestContext & context)
Returns
A pointer to json response if it was produced successfully and stored in the context or nullptr otherwise.

◆ GetTaskInheritedDeadline()

engine::Deadline server::request::GetTaskInheritedDeadline ( )
noexcept

Returns TaskInheritedData::deadline, or an unreachable engine::Deadline if none was set.

Note
Use this method to set the deadline for tasks.

◆ GetTaskInheritedOriginalDeadline()

std::optional< TaskInheritedOriginalDeadline > server::request::GetTaskInheritedOriginalDeadline ( )
noexcept

Returns TaskInheritedData::original_deadline, or std::nullopt if the header was absent or invalid.

Warning
Do not use this method to set the deadline for tasks. It is intended for deadline propagation only. Use GetTaskInheritedDeadline() to set the deadline for tasks.

◆ GetTaskInheritedQueryParameter()

const std::string & server::request::GetTaskInheritedQueryParameter ( std::string_view name)

Get a query parameter from server::http::HttpRequest that is handled by the current task hierarchy.

Returns
Parameter value or an empty string, if none such

◆ HasPropagatedHeader()

bool server::request::HasPropagatedHeader ( std::string_view header_name)

Checks whether specified header exists in server::http::HttpRequest that is handled by the current task hierarchy.

Returns
true if the header exists, false otherwise

◆ HasTaskInheritedQueryParameter()

bool server::request::HasTaskInheritedQueryParameter ( std::string_view name)

Checks whether specified query parameter exists in server::http::HttpRequest that is handled by the current task hierarchy.

Returns
true if the parameter exists, false otherwise

◆ SetClientMetricsShard()

void server::request::SetClientMetricsShard ( std::string_view path,
utils::statistics::LabelsSpan labels )

Set the client metrics shard (path + labels) for requests performed by the current task and its child tasks.

When set, supporting clients additionally accumulate their metrics on a new subpath with the provided labels. It is a client-side counterpart of server::request::RequestContext::SetHandlerMetricsShard.

The setting lives until the end of the current task and is inherited by child tasks.

Supported by:

  • HTTP client: timings, errors and reply-statuses destination metrics are accumulated on httpclient.<path>.* with the http_destination label and the provided labels. Requests without destination metrics (e.g. when destination-metrics-auto-max-size of http-client-core is reached) are not accounted in the shard.
Note
Labels should be lexicographically sorted by name and must not contain http_destination and version.
See also
ClientMetricsShardScope

◆ SetRequestJson()

formats::json::Value & server::request::SetRequestJson ( RequestContext & context,
formats::json::Value request_json )

Saves a parsed json request to the context.

Returns
A reference to the saved json.

◆ SetResponseJson()

formats::json::Value & server::request::SetResponseJson ( RequestContext & context,
formats::json::Value request_json )

Saves a json response to the context.

Returns
A reference to the saved json.

Variable Documentation

◆ kTaskInheritedData

engine::TaskInheritedVariable<TaskInheritedData> server::request::kTaskInheritedData
extern
See also
TaskInheritedData for details on the contents.