userver: ugrpc::server::MiddlewareBase Class Reference
Loading...
Searching...
No Matches
ugrpc::server::MiddlewareBase Class Reference

#include <userver/ugrpc/server/middlewares/base.hpp>

Detailed Description

+ Inheritance diagram for ugrpc::server::MiddlewareBase:

Public Member Functions

 MiddlewareBase (const MiddlewareBase &)=delete
 
MiddlewareBaseoperator= (const MiddlewareBase &)=delete
 
MiddlewareBaseoperator= (MiddlewareBase &&)=delete
 
virtual void OnCallStart (MiddlewareCallContext &context) const
 This hook is invoked once per Call (RPC), after the message metadata is received, but before the handler function is called.
 
virtual void PostRecvMessage (MiddlewareCallContext &context, google::protobuf::Message &request) const
 The function is invoked after each received message.
 
virtual void PreSendMessage (MiddlewareCallContext &context, google::protobuf::Message &response) const
 The function is invoked before each sended message.
 
virtual void PreSendStatus (MiddlewareCallContext &context, grpc::Status &status) const
 The function is invoked before sending the final status of the call.
 
virtual void OnCallFinish (MiddlewareCallContext &context, const std::optional< grpc::Status > &status) const
 This hook is invoked once per Call (RPC), after the handler function has finished execution and the final status is determined.
 

Member Function Documentation

◆ OnCallFinish()

virtual void ugrpc::server::MiddlewareBase::OnCallFinish ( MiddlewareCallContext context,
const std::optional< grpc::Status > &  status 
) const
virtual

This hook is invoked once per Call (RPC), after the handler function has finished execution and the final status is determined.

OnCallFinish is called exactly once per Call (RPC), regardless of whether the call succeeded or failed. It's the final middleware hook in the call chain. This is useful for cleanup operations, logging, or metrics collection that should happen after the RPC is completely processed.

Parameters
contextThe middleware call context containing call information
statusThe final status of the call, if available

◆ OnCallStart()

virtual void ugrpc::server::MiddlewareBase::OnCallStart ( MiddlewareCallContext context) const
virtual

This hook is invoked once per Call (RPC), after the message metadata is received, but before the handler function is called.

If all OnCallStart succeeded => OnCallFinish will invoked after a success method call.

Reimplemented in ugrpc::server::middlewares::baggage::Middleware, and ugrpc::server::middlewares::deadline_propagation::Middleware.

◆ PostRecvMessage()

virtual void ugrpc::server::MiddlewareBase::PostRecvMessage ( MiddlewareCallContext context,
google::protobuf::Message &  request 
) const
virtual

The function is invoked after each received message.

PostRecvMessage is called:

  • unary: exactly once per Call (RPC)
  • stream: 0, 1 or more times

Reimplemented in grpc_protovalidate::server::Middleware.

◆ PreSendMessage()

virtual void ugrpc::server::MiddlewareBase::PreSendMessage ( MiddlewareCallContext context,
google::protobuf::Message &  response 
) const
virtual

The function is invoked before each sended message.

PreSendMessage is called:

  • unary: 0 or 1 per Call (RPC), depending on whether the RPC returns a response or a failed status
  • stream: once per response message, that is, 0, 1, more times per Call (RPC).

◆ PreSendStatus()

virtual void ugrpc::server::MiddlewareBase::PreSendStatus ( MiddlewareCallContext context,
grpc::Status &  status 
) const
virtual

The function is invoked before sending the final status of the call.

PreSendStatus is called exactly once per Call (RPC), right before sending the final gRPC status to the client. This allows middlewares to inspect and potentially modify the status that will be sent to the client.

Reimplemented in ugrpc::server::middlewares::deadline_propagation::Middleware.


The documentation for this class was generated from the following file: