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,
test::{TestClient, TestRequestBuilder},
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"));
async fn check(app: impl Endpoint, domain: Option<&str>, res: &str) {
let cli = TestClient::new(app);
let mut req = cli.get("/");
if let Some(domain) = domain {
req = req.header(header::HOST, domain);
}
let resp = req.send().await;
resp.assert_status_is_ok();
resp.assert_text(res).await;
}
check(&app, Some("example.com"), "1").await;
check(&app, Some("www.abc.com"), "2").await;
check(&app, Some("a.b.example.com"), "3").await;
check(&app, Some("rust-lang.org"), "4").await;
check(&app, None, "4").await;
Implementations
sourceimpl RouteDomain
impl RouteDomain
sourcepub fn at<E>(self, pattern: impl AsRef<str>, ep: E) -> Selfwhere
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn at<E>(self, pattern: impl AsRef<str>, ep: E) -> Selfwhere
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 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
Mutably borrows from an owned value. Read more