Struct OriginalUri
pub struct OriginalUri(pub Uri);Expand description
Extractor that gets the original request URI regardless of nesting.
This is necessary since Uri, when used as an extractor, will
have the prefix stripped if used in a nested service.
ยงExample
use axum::{
routing::get,
Router,
extract::OriginalUri,
http::Uri
};
let api_routes = Router::new()
.route(
"/users",
get(|uri: Uri, OriginalUri(original_uri): OriginalUri| async {
// `uri` is `/users`
// `original_uri` is `/api/users`
}),
);
let app = Router::new().nest("/api", api_routes);ยงExtracting via request extensions
OriginalUri can also be accessed from middleware via request extensions.
This is useful for example with Trace to
create a span that contains the full path, if your service might be nested:
use axum::{
Router,
extract::OriginalUri,
http::Request,
routing::get,
};
use tower_http::trace::TraceLayer;
let api_routes = Router::new()
.route("/users/{id}", get(|| async { /* ... */ }))
.layer(
TraceLayer::new_for_http().make_span_with(|req: &Request<_>| {
let path = if let Some(path) = req.extensions().get::<OriginalUri>() {
// This will include `/api`
path.0.path().to_owned()
} else {
// The `OriginalUri` extension will always be present if using
// `Router` unless another extractor or middleware has removed it
req.uri().path().to_owned()
};
tracing::info_span!("http-request", %path)
}),
);
let app = Router::new().nest("/api", api_routes);Tuple Fieldsยง
ยง0: UriMethods from Deref<Target = Uri>ยง
pub fn path_and_query(&self) -> Option<&PathAndQuery>
pub fn path_and_query(&self) -> Option<&PathAndQuery>
Returns the path & query components of the Uri
pub fn path(&self) -> &str
pub fn path(&self) -> &str
Get the path of this Uri.
Both relative and absolute URIs contain a path component, though it might be the empty string. The path component is case sensitive.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|--------|
|
pathIf the URI is * then the path component is equal to *.
ยงExamples
A relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert_eq!(uri.path(), "/hello/world");An absolute URI
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert_eq!(uri.path(), "/hello/world");pub fn scheme(&self) -> Option<&Scheme>
pub fn scheme(&self) -> Option<&Scheme>
Get the scheme of this Uri.
The URI scheme refers to a specification for assigning identifiers within that scheme. Only absolute URIs contain a scheme component, but not all absolute URIs will contain a scheme component. Although scheme names are case-insensitive, the canonical form is lowercase.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-|
|
schemeยงExamples
Absolute URI
use http::uri::{Scheme, Uri};
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert_eq!(uri.scheme(), Some(&Scheme::HTTP));Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.scheme().is_none());pub fn scheme_str(&self) -> Option<&str>
pub fn scheme_str(&self) -> Option<&str>
Get the scheme of this Uri as a &str.
ยงExample
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert_eq!(uri.scheme_str(), Some("http"));Get the authority of this Uri.
The authority is a hierarchical element for naming authority such that the remainder of the URI is delegated to that authority. For HTTP, the authority consists of the host and port. The host portion of the authority is case-insensitive.
The authority also includes a username:password component, however
the use of this is deprecated and should be avoided.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-------------------------------|
|
authorityยงExamples
Absolute URI
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
assert_eq!(uri.authority().map(|a| a.as_str()), Some("example.org:80"));Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.authority().is_none());pub fn host(&self) -> Option<&str>
pub fn host(&self) -> Option<&str>
Get the host of this Uri.
The host subcomponent of authority is identified by an IP literal encapsulated within square brackets, an IPv4 address in dotted- decimal form, or a registered name. The host subcomponent is case-insensitive.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|---------|
|
hostยงExamples
Absolute URI
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
assert_eq!(uri.host(), Some("example.org"));Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.host().is_none());pub fn port(&self) -> Option<Port<&str>>
pub fn port(&self) -> Option<Port<&str>>
Get the port part of this Uri.
The port subcomponent of authority is designated by an optional port
number following the host and delimited from it by a single colon (โ:โ)
character. It can be turned into a decimal port number with the as_u16
method or as a str with the as_str method.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-|
|
portยงExamples
Absolute URI with port
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
let port = uri.port().unwrap();
assert_eq!(port.as_u16(), 80);Absolute URI without port
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert!(uri.port().is_none());Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.port().is_none());pub fn port_u16(&self) -> Option<u16>
pub fn port_u16(&self) -> Option<u16>
Get the port of this Uri as a u16.
ยงExample
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
assert_eq!(uri.port_u16(), Some(80));pub fn query(&self) -> Option<&str>
pub fn query(&self) -> Option<&str>
Get the query string of this Uri, starting after the ?.
The query component contains non-hierarchical data that, along with data in the path component, serves to identify a resource within the scope of the URIโs scheme and naming authority (if any). The query component is indicated by the first question mark (โ?โ) character and terminated by a number sign (โ#โ) character or by the end of the URI.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-------------------|
|
queryยงExamples
Absolute URI
let uri: Uri = "http://example.org/hello/world?key=value".parse().unwrap();
assert_eq!(uri.query(), Some("key=value"));Relative URI with a query string component
let uri: Uri = "/hello/world?key=value&foo=bar".parse().unwrap();
assert_eq!(uri.query(), Some("key=value&foo=bar"));Relative URI without a query string component
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.query().is_none());Trait Implementationsยง
ยงimpl Clone for OriginalUri
impl Clone for OriginalUri
ยงfn clone(&self) -> OriginalUri
fn clone(&self) -> OriginalUri
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreยงimpl Debug for OriginalUri
impl Debug for OriginalUri
ยงimpl Deref for OriginalUri
impl Deref for OriginalUri
ยงimpl DerefMut for OriginalUri
impl DerefMut for OriginalUri
ยงfn deref_mut(&mut self) -> &mut <OriginalUri as Deref>::Target
fn deref_mut(&mut self) -> &mut <OriginalUri as Deref>::Target
ยงimpl<S> FromRequestParts<S> for OriginalUri
impl<S> FromRequestParts<S> for OriginalUri
ยงtype Rejection = Infallible
type Rejection = Infallible
ยงasync fn from_request_parts(
parts: &mut Parts,
state: &S,
) -> Result<OriginalUri, <OriginalUri as FromRequestParts<S>>::Rejection>
async fn from_request_parts( parts: &mut Parts, state: &S, ) -> Result<OriginalUri, <OriginalUri as FromRequestParts<S>>::Rejection>
Auto Trait Implementationsยง
impl !Freeze for OriginalUri
impl RefUnwindSafe for OriginalUri
impl Send for OriginalUri
impl Sync for OriginalUri
impl Unpin for OriginalUri
impl UnwindSafe for OriginalUri
Blanket Implementationsยง
Sourceยงimpl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Sourceยงfn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Sourceยงfn adapt_into(self) -> D
fn adapt_into(self) -> D
Sourceยงimpl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Sourceยงfn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Sourceยงimpl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Sourceยงfn arrays_into(self) -> C
fn arrays_into(self) -> C
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
Sourceยงimpl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Sourceยงtype Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Sourceยงfn components_from(colors: C) -> T
fn components_from(colors: C) -> T
ยงimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
ยงfn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.ยงfn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.ยงfn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Anyโs vtable from &Traitโs.ยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Anyโs vtable from &mut Traitโs.ยงimpl<T> DowncastSend for T
impl<T> DowncastSend for T
ยงimpl<T> DowncastSync for T
impl<T> DowncastSync for T
Sourceยงimpl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Sourceยงfn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.ยงimpl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
ยงtype Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
ยงfn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Sourceยงimpl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Sourceยงfn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Instrument for T
impl<T> Instrument for T
ยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงimpl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Sourceยงfn into_angle(self) -> U
fn into_angle(self) -> U
T.Sourceยงimpl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Sourceยงtype Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Sourceยงfn into_color(self) -> U
fn into_color(self) -> U
Sourceยงimpl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Sourceยงfn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreยงimpl<T, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
impl<T, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
ยงfn into_reactive_value(self) -> T
fn into_reactive_value(self) -> T
self into a T.Sourceยงimpl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Sourceยงfn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Pointable for T
impl<T> Pointable for T
ยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
ยงimpl<T> SerializableKey for T
impl<T> SerializableKey for T
ยงimpl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
ยงfn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
ยงfn into_taken(self) -> T
fn into_taken(self) -> T
Sourceยงimpl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Sourceยงtype Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Sourceยงfn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Sourceยงimpl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Sourceยงfn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more