#include <userver/ugrpc/server/middlewares/base.hpp>
Context for middleware-specific data during gRPC call.
Public Member Functions | |
| void | SetError (grpc::Status &&status) noexcept |
| Aborts the RPC, returning the specified status to the upstream client, see details below. | |
| RpcType | GetRpcType () const noexcept |
| const dynamic_config::Snapshot & | GetInitialDynamicConfig () const |
| Get values extracted from dynamic_config. Snapshot will be deleted when the last middleware completes. | |
| std::optional< std::size_t > | GetLatestRequestSizeBytes () const noexcept |
| Serialized size of the request message most recently received on this call. | |
| std::optional< std::size_t > | GetLatestResponseSizeBytes () const noexcept |
| Serialized size of the response message most recently sent on this call. | |
| grpc::ServerContextBase & | GetServerContext () |
| const grpc::ServerContextBase & | GetServerContext () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| std::string_view | GetCallName () const |
| Name of the RPC in the format full.path.ServiceName/MethodName. | |
| std::string_view | GetServiceName () const |
| Get name of gRPC service. | |
| std::string_view | GetMethodName () const |
| Get name of called gRPC method. | |
| tracing::Span & | GetSpan () |
| Get the span of the current RPC. | |
| utils::OptionalRef< google::protobuf::Arena > | GetArena () const |
| Borrow the call's protobuf arena. | |
| std::shared_ptr< google::protobuf::Arena > | GetArenaSharedPtr () const noexcept |
| Share ownership of the call's protobuf arena. | |
| utils::AnyStorage< StorageContext > & | GetStorageContext () |
| Returns call context for storing per-call custom data. | |
|
inherited |
Borrow the call's protobuf arena.
|
noexceptinherited |
Share ownership of the call's protobuf arena.
|
noexcept |
Serialized size of the request message most recently received on this call.
This is the size of the wire buffer, which is cheaper than calling google::protobuf::Message::ByteSizeLong on the parsed request. For a streaming RPC it is the latest message read so far, not a distinguished final request of the RPC: another request message may still arrive.
While the call is running, only the read side may call this. On a bidirectional stream PostRecvMessage runs concurrently with the write side, and calling this from PreSendMessage or PreSendStatus is a data race. OnCallFinish runs after both sides have completed.
|
noexcept |
Serialized size of the response message most recently sent on this call.
This is the size of the wire buffer, which is cheaper than calling google::protobuf::Message::ByteSizeLong on the response. For a streaming RPC it is the latest message sent so far, not a distinguished final response of the RPC: another response message may still be sent.
The response is serialized after PreSendMessage and PreSendStatus, because those hooks may modify it or replace it with an error. In those hooks the size is empty for unary and client-streaming RPCs, and it is the previous message for a response stream. OnCallFinish runs after serialization; there it is empty if serializing the final response failed.
While the call is running, only the write side may call this. On a bidirectional stream PreSendMessage runs concurrently with the read side, and calling this from PostRecvMessage is a data race. OnCallFinish runs after both sides have completed.
|
noexcept |
|
inherited |
|
inherited |
Returns call context for storing per-call custom data.
The context can be used to pass data from server middleware to client handler or from one middleware to another one.
In authentication middleware:
In client handler:
|
noexcept |
Aborts the RPC, returning the specified status to the upstream client, see details below.
It should be the last command in middlewares hooks.
If that method is called in methods:
Example usage