#include <userver/server/request/request_context.hpp>
Stores request-specific data during request processing.
For example: you can store some data in HandleRequestThrow()
method and access this data in GetResponseDataForLogging()
method.
- Examples
- postgresql/functional_tests/basic_chaos/postgres_service.cpp, samples/config_service/config_service.cpp, samples/flatbuf_service/flatbuf_service.cpp, samples/grpc_service/grpc_service.cpp, samples/hello_service/hello_service.cpp, samples/http_caching/http_caching.cpp, samples/mongo_service/mongo_service.cpp, samples/multipart_service/service.cpp, samples/postgres_auth/auth_bearer.cpp, samples/postgres_auth/postgres_service.cpp, samples/postgres_service/postgres_service.cpp, samples/redis_service/redis_service.cpp, samples/testsuite-support/src/logcapture.cpp, samples/testsuite-support/src/metrics.cpp, samples/testsuite-support/src/metrics.hpp, samples/testsuite-support/src/now.cpp, samples/testsuite-support/src/testpoint.cpp, and samples/websocket_service/websocket_service.cpp.
Definition at line 25 of file request_context.hpp.
|
| RequestContext (RequestContext &&) noexcept |
|
| RequestContext (const RequestContext &)=delete |
|
template<typename Data > |
Data & | SetUserData (Data data) |
| Stores user data if it was not previously stored in this.
|
|
template<typename Data , typename... Args> |
Data & | EmplaceUserData (Args &&... args) |
| Emplaces user data if it was not previously stored in this.
|
|
template<typename Data > |
Data & | GetUserData () |
|
template<typename Data > |
const Data & | GetUserData () const |
|
template<typename Data > |
std::remove_reference_t< Data > * | GetUserDataOptional () |
|
template<typename Data > |
const std::remove_reference_t< Data > * | GetUserDataOptional () const |
|
void | EraseUserData () |
| Erases the user data.
|
|
template<typename Data > |
Data & | SetData (std::string name, Data data) |
| Stores the data with specified name if it was not previously stored in this.
|
|
template<typename Data , typename... Args> |
Data & | EmplaceData (std::string name, Args &&... args) |
| Emplaces the data with specified name if it was not previously stored in this.
|
|
template<typename Data > |
Data & | GetData (std::string_view name) |
|
template<typename Data > |
const Data & | GetData (std::string_view name) const |
|
template<typename Data > |
std::remove_reference_t< Data > * | GetDataOptional (std::string_view name) |
|
template<typename Data > |
const std::remove_reference_t< Data > * | GetDataOptional (std::string_view name) const |
|
void | EraseData (std::string_view name) |
| Erase data with specified name.
|
|
impl::InternalRequestContext & | GetInternalContext () |
|
◆ EmplaceData()
template<typename Data , typename... Args>
Data & server::request::RequestContext::EmplaceData |
( |
std::string | name, |
|
|
Args &&... | args ) |
Emplaces the data with specified name if it was not previously stored in this.
- Exceptions
-
std::runtime_error | if data with such name was already stored. |
Definition at line 187 of file request_context.hpp.
◆ EmplaceUserData()
template<typename Data , typename... Args>
Data & server::request::RequestContext::EmplaceUserData |
( |
Args &&... | args | ) |
|
Emplaces user data if it was not previously stored in this.
- Exceptions
-
std::runtime_error | if user data was already stored. |
Definition at line 141 of file request_context.hpp.
◆ EraseData()
void server::request::RequestContext::EraseData |
( |
std::string_view | name | ) |
|
|
inline |
◆ EraseUserData()
void server::request::RequestContext::EraseUserData |
( |
| ) |
|
|
inline |
◆ GetData() [1/2]
template<typename Data >
Data & server::request::RequestContext::GetData |
( |
std::string_view | name | ) |
|
◆ GetData() [2/2]
template<typename Data >
const Data & server::request::RequestContext::GetData |
( |
std::string_view | name | ) |
const |
- Returns
- Stored data with specified name.
- Exceptions
-
std::runtime_error | if no data was stored |
std::bad_any_cast | if data of different type was stored |
Definition at line 199 of file request_context.hpp.
◆ GetDataOptional() [1/2]
template<typename Data >
std::remove_reference_t< Data > * server::request::RequestContext::GetDataOptional |
( |
std::string_view | name | ) |
|
- Returns
- Stored data with specified name or nullptr if no data found.
- Exceptions
-
std::bad_any_cast | if data of different type was stored. |
Definition at line 205 of file request_context.hpp.
◆ GetDataOptional() [2/2]
template<typename Data >
const std::remove_reference_t< Data > * server::request::RequestContext::GetDataOptional |
( |
std::string_view | name | ) |
const |
- Returns
- Stored data with specified name or nullptr if no data found.
- Exceptions
-
std::bad_any_cast | if data of different type was stored. |
Definition at line 212 of file request_context.hpp.
◆ GetUserData() [1/2]
template<typename Data >
Data & server::request::RequestContext::GetUserData |
( |
| ) |
|
- Returns
- Stored user data
- Exceptions
-
std::runtime_error | if no data was stored |
std::bad_any_cast | if data of different type was stored |
Definition at line 148 of file request_context.hpp.
◆ GetUserData() [2/2]
template<typename Data >
const Data & server::request::RequestContext::GetUserData |
( |
| ) |
const |
- Returns
- Stored user data
- Exceptions
-
std::runtime_error | if no data was stored |
std::bad_any_cast | if data of different type was stored |
Definition at line 153 of file request_context.hpp.
◆ GetUserDataOptional() [1/2]
template<typename Data >
std::remove_reference_t< Data > * server::request::RequestContext::GetUserDataOptional |
( |
| ) |
|
- Returns
- A pointer to data of type Data if it was stored before during current request processing or nullptr otherwise
Definition at line 159 of file request_context.hpp.
◆ GetUserDataOptional() [2/2]
template<typename Data >
const std::remove_reference_t< Data > * server::request::RequestContext::GetUserDataOptional |
( |
| ) |
const |
- Returns
- A pointer to data of type Data if it was stored before during current request processing or nullptr otherwise
Definition at line 165 of file request_context.hpp.
◆ SetData()
template<typename Data >
Data & server::request::RequestContext::SetData |
( |
std::string | name, |
|
|
Data | data ) |
◆ SetUserData()
template<typename Data >
Data & server::request::RequestContext::SetUserData |
( |
Data | data | ) |
|
Stores user data if it was not previously stored in this.
- Exceptions
-
std::runtime_error | if user data was already stored. |
Definition at line 128 of file request_context.hpp.
The documentation for this class was generated from the following file: