#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/hello_service/src/hello_handler.cpp, samples/hello_service/src/hello_handler.hpp, samples/http_caching/http_caching.cpp, samples/kafka_service/src/producer_handler.cpp, samples/kafka_service/src/producer_handler.hpp, 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 191 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 143 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 203 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 209 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 215 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 150 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 155 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 161 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 167 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 127 of file request_context.hpp.
The documentation for this class was generated from the following file: