Struct tonic::Request [−][src]
pub struct Request<T> { /* fields omitted */ }
Expand description
A gRPC request and metadata from an RPC call.
Implementations
Create a new gRPC request.
Request::new(HelloRequest {
name: "Bob".into(),
});
Get a reference to the custom request metadata.
Get a mutable reference to the request metadata.
Consumes self
, returning the message
Get the remote address of this connection.
This will return None
if the IO
type used
does not implement Connected
. This currently,
only works on the server side.
This is supported on crate feature transport
only.
transport
only.Get the peer certificates of the connected client.
This is used to fetch the certificates from the TLS session
and is mostly used for mTLS. This currently only returns
Some
on the server side of the transport
server with
TLS enabled connections.
Set the max duration the request is allowed to take.
Requires the server to support the grpc-timeout
metadata, which Tonic does.
The duration will be formatted according to the spec and use the most precise unit possible.
Example:
use std::time::Duration;
use tonic::Request;
let mut request = Request::new(());
request.set_timeout(Duration::from_secs(30));
let value = request.metadata().get("grpc-timeout").unwrap();
assert_eq!(
value,
// equivalent to 30 seconds
"30000000u"
);
Returns a reference to the associated extensions.
Returns a mutable reference to the associated extensions.
Example
Extensions can be set in interceptors:
use tonic::{Request, service::interceptor};
struct MyExtension {
some_piece_of_data: String,
}
interceptor(|mut request: Request<()>| {
request.extensions_mut().insert(MyExtension {
some_piece_of_data: "foo".to_string(),
});
Ok(request)
});
And picked up by RPCs:
use tonic::{async_trait, Status, Request, Response};
#[async_trait]
impl TestService for MyService {
async fn handler(&self, req: Request<Input>) -> Result<Response<Output>, Status> {
let value: &MyExtension = req.extensions().get::<MyExtension>().unwrap();
Ok(Response::new(Output {}))
}
}
Trait Implementations
Wrap the input message T
in a tonic::Request
type Stream = T
type Stream = T
The RPC request stream type
Wrap the stream of messages in a tonic::Request
Auto Trait Implementations
impl<T> !RefUnwindSafe for Request<T>
impl<T> !UnwindSafe for Request<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
pub fn vzip(self) -> V
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more