Struct poem::RouteDomain
source · [−]pub struct RouteDomain { /* private fields */ }
Expand description
Routing object for HOST
header
Errors
Example
use poem::{endpoint::make_sync, handler, http::header, Endpoint, Request, RouteDomain};
let app = RouteDomain::new()
.at("example.com", make_sync(|_| "1"))
.at("www.+.com", make_sync(|_| "2"))
.at("*.example.com", make_sync(|_| "3"))
.at("*", make_sync(|_| "4"));
fn make_request(host: &str) -> Request {
Request::builder().header(header::HOST, host).finish()
}
async fn do_request(app: &RouteDomain, req: Request) -> String {
app.call(req)
.await
.unwrap()
.into_body()
.into_string()
.await
.unwrap()
}
assert_eq!(do_request(&app, make_request("example.com")).await, "1");
assert_eq!(do_request(&app, make_request("www.abc.com")).await, "2");
assert_eq!(do_request(&app, make_request("a.b.example.com")).await, "3");
assert_eq!(do_request(&app, make_request("rust-lang.org")).await, "4");
assert_eq!(do_request(&app, Request::default()).await, "4");
Implementations
sourceimpl RouteDomain
impl RouteDomain
sourcepub fn at<E>(self, pattern: impl AsRef<str>, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn at<E>(self, pattern: impl AsRef<str>, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
sourcepub fn try_at<E>(
self,
pattern: impl AsRef<str>,
ep: E
) -> Result<Self, RouteError> where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn try_at<E>(
self,
pattern: impl AsRef<str>,
ep: E
) -> Result<Self, RouteError> where
E: IntoEndpoint,
E::Endpoint: 'static,
Attempts to add an Endpoint to the specified domain pattern.
Trait Implementations
sourceimpl Default for RouteDomain
impl Default for RouteDomain
sourcefn default() -> RouteDomain
fn default() -> RouteDomain
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for RouteDomain
impl Send for RouteDomain
impl Sync for RouteDomain
impl Unpin for RouteDomain
impl !UnwindSafe for RouteDomain
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more