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§
source§impl 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§
source§impl Default for RouteDomain
impl Default for RouteDomain
source§fn default() -> RouteDomain
fn default() -> RouteDomain
Returns the “default value” for a type. Read more
source§impl Endpoint for RouteDomain
impl Endpoint for RouteDomain
Auto Trait Implementations§
impl Freeze for RouteDomain
impl !RefUnwindSafe for RouteDomain
impl Send for RouteDomain
impl Sync for RouteDomain
impl Unpin for RouteDomain
impl !UnwindSafe for RouteDomain
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
source§impl<T> EndpointExt for Twhere
T: IntoEndpoint,
impl<T> EndpointExt for Twhere
T: IntoEndpoint,
source§fn boxed<'a>(self) -> BoxEndpoint<'a, <Self::Endpoint as Endpoint>::Output>where
Self: Sized + 'a,
fn boxed<'a>(self) -> BoxEndpoint<'a, <Self::Endpoint as Endpoint>::Output>where
Self: Sized + 'a,
Wrap the endpoint in a Box.
source§fn with<T>(self, middleware: T) -> T::Output
fn with<T>(self, middleware: T) -> T::Output
Use middleware to transform this endpoint. Read more
source§fn data<T>(self, data: T) -> AddDataEndpoint<Self::Endpoint, T>
fn data<T>(self, data: T) -> AddDataEndpoint<Self::Endpoint, T>
Attach a state data to the endpoint, similar to
with(AddData(T))
. Read moresource§fn data_opt<T>(
self,
data: Option<T>
) -> EitherEndpoint<AddDataEndpoint<Self::Endpoint, T>, Self>
fn data_opt<T>( self, data: Option<T> ) -> EitherEndpoint<AddDataEndpoint<Self::Endpoint, T>, Self>
if
data
is Some(T)
then attach the value to the endpoint.source§fn after<F, Fut, T>(self, f: F) -> After<Self::Endpoint, F>
fn after<F, Fut, T>(self, f: F) -> After<Self::Endpoint, F>
Maps the output of this endpoint. Read more
source§fn around<F, Fut, R>(self, f: F) -> Around<Self::Endpoint, F>
fn around<F, Fut, R>(self, f: F) -> Around<Self::Endpoint, F>
Maps the request and response of this endpoint. Read more
source§fn map_to_response(self) -> MapToResponse<Self::Endpoint>where
Self: Sized,
fn map_to_response(self) -> MapToResponse<Self::Endpoint>where
Self: Sized,
source§fn to_response(self) -> ToResponse<Self::Endpoint>where
Self: Sized,
fn to_response(self) -> ToResponse<Self::Endpoint>where
Self: Sized,
source§fn map<F, Fut, R, R2>(self, f: F) -> Map<Self::Endpoint, F>
fn map<F, Fut, R, R2>(self, f: F) -> Map<Self::Endpoint, F>
Maps the response of this endpoint. Read more
source§fn catch_all_error<F, Fut, R>(self, f: F) -> CatchAllError<Self, F, R>
fn catch_all_error<F, Fut, R>(self, f: F) -> CatchAllError<Self, F, R>
Catch all errors and convert it into a response. Read more
source§fn catch_error<F, Fut, R, ErrType>(
self,
f: F
) -> CatchError<Self, F, R, ErrType>
fn catch_error<F, Fut, R, ErrType>( self, f: F ) -> CatchError<Self, F, R, ErrType>
Catch the specified type of error and convert it into a response. Read more
source§fn inspect_all_err<F>(self, f: F) -> InspectAllError<Self, F>
fn inspect_all_err<F>(self, f: F) -> InspectAllError<Self, F>
Does something with each error. Read more
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEndpoint for Twhere
T: Endpoint,
impl<T> IntoEndpoint for Twhere
T: Endpoint,
source§fn into_endpoint(self) -> <T as IntoEndpoint>::Endpoint
fn into_endpoint(self) -> <T as IntoEndpoint>::Endpoint
Converts this object into endpoint.
source§impl<T> TowerCompatExt for T
impl<T> TowerCompatExt for T
source§fn compat<ResBody, Err, Fut>(self) -> TowerCompatEndpoint<Self>where
ResBody: Body + Send + Sync + 'static,
ResBody::Data: Into<Bytes> + Send + 'static,
ResBody::Error: StdError + Send + Sync + 'static,
Err: Into<Error>,
Self: Service<Request<BoxBody<Bytes, Error>>, Response = Response<ResBody>, Error = Err, Future = Fut> + Clone + Send + Sync + Sized + 'static,
Fut: Future<Output = Result<Response<ResBody>, Err>> + Send + 'static,
fn compat<ResBody, Err, Fut>(self) -> TowerCompatEndpoint<Self>where
ResBody: Body + Send + Sync + 'static,
ResBody::Data: Into<Bytes> + Send + 'static,
ResBody::Error: StdError + Send + Sync + 'static,
Err: Into<Error>,
Self: Service<Request<BoxBody<Bytes, Error>>, Response = Response<ResBody>, Error = Err, Future = Fut> + Clone + Send + Sync + Sized + 'static,
Fut: Future<Output = Result<Response<ResBody>, Err>> + Send + 'static,
Available on crate feature
tower-compat
only.Converts a tower service to a poem endpoint.