Struct google_cloud_gax::grpc::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>
T in a tonic::Requestsourceimpl<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
type Message = <T as Stream>::Item
type Message = <T as Stream>::Item
sourcefn into_streaming_request(self) -> Request<T>
fn into_streaming_request(self) -> Request<T>
tonic::RequestAuto 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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
sourcefn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request