#[non_exhaustive]pub struct ReceivedRequest { /* private fields */ }Expand description
The HTTP request a transcoded gRPC call was made from, as the proxy received it: its method, its path and query, and the gRPC path of the RPC the matched binding selected.
The path is the one on the request line, before a router the proxy is
nested in strips its prefix, so an alias or a public prefix stays visible.
An absolute-form target (any HTTP/2 request, an HTTP/1.1 request through a
forward proxy) records its path and query alone, so one request records the
same value over either protocol. No header the client sends
(x-original-uri, forwarding headers) changes it.
§Examples
use structured_proxy::ReceivedRequest;
// What a tonic handler behind the proxy does with it.
fn target(request: &tonic::Request<()>) -> Option<String> {
let received = request.extensions().get::<ReceivedRequest>()?;
Some(format!("{} {}", received.method(), received.path_and_query()))
}
let received = ReceivedRequest::new(
http::Method::POST,
http::uri::PathAndQuery::from_static("/v1/orgs/42:suspend?dry=1"),
http::uri::PathAndQuery::from_static("/acme.v1.Orgs/Suspend"),
);
let mut request = tonic::Request::new(());
request.extensions_mut().insert(received);
assert_eq!(target(&request).as_deref(), Some("POST /v1/orgs/42:suspend?dry=1"));Implementations§
Source§impl ReceivedRequest
impl ReceivedRequest
Sourcepub fn new(
method: Method,
path_and_query: PathAndQuery,
rpc: PathAndQuery,
) -> Self
pub fn new( method: Method, path_and_query: PathAndQuery, rpc: PathAndQuery, ) -> Self
A request received as method path_and_query, transcoded to the RPC
at the gRPC path rpc. The view an upstream’s own tests hand it.
Sourcepub fn method(&self) -> &Method
pub fn method(&self) -> &Method
The HTTP method as received: HEAD on a route bound to GET stays
HEAD, and a custom binding’s method is itself.
Sourcepub fn path_and_query(&self) -> &PathAndQuery
pub fn path_and_query(&self) -> &PathAndQuery
The path and query as received, percent-encoding untouched.
Trait Implementations§
Source§impl Clone for ReceivedRequest
impl Clone for ReceivedRequest
Source§impl Debug for ReceivedRequest
impl Debug for ReceivedRequest
impl Eq for ReceivedRequest
Source§impl PartialEq for ReceivedRequest
impl PartialEq for ReceivedRequest
impl StructuralPartialEq for ReceivedRequest
Auto Trait Implementations§
impl !Freeze for ReceivedRequest
impl RefUnwindSafe for ReceivedRequest
impl Send for ReceivedRequest
impl Sync for ReceivedRequest
impl Unpin for ReceivedRequest
impl UnsafeUnpin for ReceivedRequest
impl UnwindSafe for ReceivedRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request