Struct madsim_tonic::Request
source · [−]pub struct Request<T> { /* private fields */ }
Expand description
A gRPC request and metadata from an RPC call.
Implementations
sourceimpl<T> Request<T>
impl<T> Request<T>
sourcepub fn new(message: T) -> Request<T>
pub fn new(message: T) -> Request<T>
Create a new gRPC request.
Request::new(HelloRequest {
name: "Bob".into(),
});
sourcepub fn metadata(&self) -> &MetadataMap
pub fn metadata(&self) -> &MetadataMap
Get a reference to the custom request metadata.
sourcepub fn metadata_mut(&mut self) -> &mut MetadataMap
pub fn metadata_mut(&mut self) -> &mut MetadataMap
Get a mutable reference to the request metadata.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes self
, returning the message
sourcepub fn remote_addr(&self) -> Option<SocketAddr>
pub fn remote_addr(&self) -> Option<SocketAddr>
Get the remote address of this connection.
This will return None
if the IO
type used
does not implement Connected
or when using a unix domain socket.
This currently only works on the server side.
sourcepub fn peer_certs(&self) -> Option<Arc<Vec<Certificate, Global>>>
pub fn peer_certs(&self) -> Option<Arc<Vec<Certificate, Global>>>
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.
sourcepub fn set_timeout(&mut self, deadline: Duration)
pub fn set_timeout(&mut self, deadline: Duration)
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"
);
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut 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
sourceimpl<T> IntoRequest<T> for Request<T>
impl<T> IntoRequest<T> for Request<T>
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
sourceimpl<T> IntoStreamingRequest for Request<T> where
T: 'static + Stream + Send,
impl<T> IntoStreamingRequest for Request<T> where
T: 'static + Stream + Send,
type Stream = T
type Stream = T
The RPC request stream type
type Message = <T as Stream>::Item
type Message = <T as Stream>::Item
The RPC request type
sourcefn into_streaming_request(self) -> Request<T>
fn into_streaming_request(self) -> Request<T>
Wrap the stream of messages in a tonic::Request
Auto Trait Implementations
impl<T> !RefUnwindSafe for Request<T>
impl<T> Send for Request<T> where
T: Send,
impl<T> Sync for Request<T> where
T: Sync,
impl<T> Unpin for Request<T> where
T: Unpin,
impl<T> !UnwindSafe for Request<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn 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;
T: Future, type Output = <T as Future>::Output;
sourcefn 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;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn 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>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn 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;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more