Stores request-specific data during request processing.
More...
#include <userver/server/request/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 (const std::string &name) |
|
template<typename Data > |
const Data & | GetData (const std::string &name) const |
|
template<typename Data > |
std::remove_reference_t< Data > * | GetDataOptional (const std::string &name) |
|
template<typename Data > |
const std::remove_reference_t< Data > * | GetDataOptional (const std::string &name) const |
|
void | EraseData (const std::string &name) |
| Erase data with specified name.
|
|
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/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 20 of file request_context.hpp.
◆ 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 168 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 131 of file request_context.hpp.
◆ EraseData()
void server::request::RequestContext::EraseData |
( |
const std::string & |
name | ) |
|
|
inline |
◆ EraseUserData()
void server::request::RequestContext::EraseUserData |
( |
| ) |
|
|
inline |
◆ GetData() [1/2]
template<typename Data >
Data & server::request::RequestContext::GetData |
( |
const std::string & |
name | ) |
|
◆ GetData() [2/2]
template<typename Data >
const Data & server::request::RequestContext::GetData |
( |
const std::string & |
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 179 of file request_context.hpp.
◆ GetDataOptional() [1/2]
template<typename Data >
std::remove_reference_t< Data > * server::request::RequestContext::GetDataOptional |
( |
const std::string & |
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 185 of file request_context.hpp.
◆ GetDataOptional() [2/2]
template<typename Data >
const std::remove_reference_t< Data > * server::request::RequestContext::GetDataOptional |
( |
const std::string & |
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 192 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 137 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 142 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 148 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 154 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 126 of file request_context.hpp.
The documentation for this class was generated from the following file: