Struct tonic::transport::Uri [−][src]
The URI component of a request.
For HTTP 1, this is included as part of the request line. From Section 5.3, Request Target:
Once an inbound connection is obtained, the client sends an HTTP request message (Section 3) with a request-target derived from the target URI. There are four distinct formats for the request-target, depending on both the method being requested and whether the request is to a proxy.
request-target = origin-form / absolute-form / authority-form / asterisk-form
The URI is structured as follows:
abc://username:[email protected]:123/path/data?key=value&key2=value2#fragid1
|-| |-------------------------------||--------| |-------------------| |-----|
| | | | |
scheme authority path query fragment
For HTTP 2.0, the URI is encoded using pseudoheaders.
Examples
use http::Uri; let uri = "/foo/bar?baz".parse::<Uri>().unwrap(); assert_eq!(uri.path(), "/foo/bar"); assert_eq!(uri.query(), Some("baz")); assert_eq!(uri.host(), None); let uri = "https://www.rust-lang.org/install.html".parse::<Uri>().unwrap(); assert_eq!(uri.scheme_str(), Some("https")); assert_eq!(uri.host(), Some("www.rust-lang.org")); assert_eq!(uri.path(), "/install.html");
Implementations
impl Uri
[src]
pub fn builder() -> Builder
[src]
Creates a new builder-style object to manufacture a Uri
.
This method returns an instance of Builder
which can be usd to
create a Uri
.
Examples
use http::Uri; let uri = Uri::builder() .scheme("https") .authority("hyper.rs") .path_and_query("/") .build() .unwrap();
pub fn from_parts(src: Parts) -> Result<Uri, InvalidUriParts>
[src]
Attempt to convert a Uri
from Parts
pub fn from_maybe_shared<T>(src: T) -> Result<Uri, InvalidUri> where
T: AsRef<[u8]> + 'static,
[src]
T: AsRef<[u8]> + 'static,
Attempt to convert a Bytes
buffer to a Uri
.
This will try to prevent a copy if the type passed is the type used internally, and will copy the data if it is not.
pub fn from_static(src: &'static str) -> Uri
[src]
Convert a Uri
from a static string.
This function will not perform any copying, however the string is checked to ensure that it is valid.
Panics
This function panics if the argument is an invalid URI.
Examples
let uri = Uri::from_static("http://example.com/foo"); assert_eq!(uri.host().unwrap(), "example.com"); assert_eq!(uri.path(), "/foo");
pub fn into_parts(self) -> Parts
[src]
Convert a Uri
into Parts
.
Note
This is just an inherent method providing the same functionality as
let parts: Parts = uri.into()
Examples
let uri: Uri = "/foo".parse().unwrap(); let parts = uri.into_parts(); assert_eq!(parts.path_and_query.unwrap(), "/foo"); assert!(parts.scheme.is_none()); assert!(parts.authority.is_none());
pub fn path_and_query(&self) -> Option<&PathAndQuery>
[src]
Returns the path & query components of the Uri
pub fn path(&self) -> &str
[src]
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:[email protected]:123/path/data?key=value&key2=value2#fragid1
|--------|
|
path
If 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>
[src]
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:[email protected]: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>
[src]
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"));
pub fn authority(&self) -> Option<&Authority>
[src]
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:[email protected]:123/path/data?key=value&key2=value2#fragid1
|-------------------------------|
|
authority
This function will be renamed to authority
in the next semver release.
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>
[src]
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:[email protected]: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>>
[src]
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:[email protected]: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>
[src]
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>
[src]
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:[email protected]: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 Uri
[src]
impl Debug for Uri
[src]
impl Default for Uri
[src]
Returns a Uri
representing /
impl Display for Uri
[src]
impl Eq for Uri
[src]
impl From<Uri> for Parts
[src]
Convert a Uri
from parts
Examples
Relative URI
let mut parts = Parts::default(); parts.path_and_query = Some("/foo".parse().unwrap()); let uri = Uri::from_parts(parts).unwrap(); assert_eq!(uri.path(), "/foo"); assert!(uri.scheme().is_none()); assert!(uri.authority().is_none());
Absolute URI
let mut parts = Parts::default(); parts.scheme = Some("http".parse().unwrap()); parts.authority = Some("foo.com".parse().unwrap()); parts.path_and_query = Some("/foo".parse().unwrap()); let uri = Uri::from_parts(parts).unwrap(); assert_eq!(uri.scheme().unwrap().as_str(), "http"); assert_eq!(uri.authority().unwrap(), "foo.com"); assert_eq!(uri.path(), "/foo");
impl From<Uri> for Endpoint
[src]
impl FromStr for Uri
[src]
type Err = InvalidUri
The associated error which can be returned from parsing.
pub fn from_str(s: &str) -> Result<Uri, InvalidUri>
[src]
impl Hash for Uri
[src]
pub fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> PartialEq<&'a str> for Uri
[src]
pub fn eq(&self, other: &&'a str) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Uri> for Uri
[src]
pub fn eq(&self, other: &Uri) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<str> for Uri
[src]
pub fn eq(&self, other: &str) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<R> Service<Uri> for HttpConnector<R> where
R: Resolve + Clone + Send + Sync + 'static,
<R as Resolve>::Future: Send,
[src]
R: Resolve + Clone + Send + Sync + 'static,
<R as Resolve>::Future: Send,
type Response = TcpStream
Responses given by the service.
type Error = ConnectError
Errors produced by the service.
type Future = HttpConnecting<R>
The future response value.
pub fn poll_ready(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(), <HttpConnector<R> as Service<Uri>>::Error>>
[src]
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(), <HttpConnector<R> as Service<Uri>>::Error>>
pub fn call(&mut self, dst: Uri) -> <HttpConnector<R> as Service<Uri>>::Future
[src]
impl<'a> TryFrom<&'a [u8]> for Uri
[src]
type Error = InvalidUri
The type returned in the event of a conversion error.
pub fn try_from(t: &'a [u8]) -> Result<Uri, <Uri as TryFrom<&'a [u8]>>::Error>
[src]
impl<'a> TryFrom<&'a String> for Uri
[src]
type Error = InvalidUri
The type returned in the event of a conversion error.
pub fn try_from(
t: &'a String
) -> Result<Uri, <Uri as TryFrom<&'a String>>::Error>
[src]
t: &'a String
) -> Result<Uri, <Uri as TryFrom<&'a String>>::Error>
impl<'a> TryFrom<&'a Uri> for Uri
[src]
type Error = Error
The type returned in the event of a conversion error.
pub fn try_from(src: &'a Uri) -> Result<Uri, <Uri as TryFrom<&'a Uri>>::Error>
[src]
impl<'a> TryFrom<&'a str> for Uri
[src]
type Error = InvalidUri
The type returned in the event of a conversion error.
pub fn try_from(t: &'a str) -> Result<Uri, <Uri as TryFrom<&'a str>>::Error>
[src]
impl TryFrom<Parts> for Uri
[src]
type Error = InvalidUriParts
The type returned in the event of a conversion error.
pub fn try_from(src: Parts) -> Result<Uri, <Uri as TryFrom<Parts>>::Error>
[src]
impl TryFrom<String> for Uri
[src]
Auto Trait Implementations
impl RefUnwindSafe for Uri
impl Send for Uri
impl Sync for Uri
impl Unpin for Uri
impl UnwindSafe for Uri
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut Tⓘ
[src]
impl<T> CallHasher for T where
T: Hash,
[src]
T: Hash,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub 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;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
pub 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;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Instrument for T
[src]
pub 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;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
pub 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;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a Tⓘ
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Tⓘ
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,
impl<T> WithSubscriber for T
[src]
pub 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>,
[src]
Notable traits for WithDispatch<T>
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
S: Into<Dispatch>,
pub 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;
[src]
Notable traits for WithDispatch<T>
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;