Struct poem::RouteDomain [−][src]
pub struct RouteDomain { /* fields omitted */ }
Expand description
Routing object for HOST
header
Errors
Example
use poem::{endpoint::make_sync, handler, http::header, Endpoint, Request, RouteDomain};
let app = RouteDomain::new()
.add("example.com", make_sync(|_| "1"))
.add("www.+.com", make_sync(|_| "2"))
.add("*.example.com", make_sync(|_| "3"))
.add("*", 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
Trait Implementations
Returns the “default value” for a type. Read more
Get the response to the request.
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
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more