mirror of
https://github.com/actix/actix-web.git
synced 2024-11-20 00:21:07 +00:00
Add doctest to verify NormalizePath middleware (#809)
This commit is contained in:
parent
24bd5b1344
commit
87284f0951
1 changed files with 23 additions and 6 deletions
|
@ -13,14 +13,30 @@ use crate::Error;
|
||||||
/// Performs following:
|
/// Performs following:
|
||||||
///
|
///
|
||||||
/// - Merges multiple slashes into one.
|
/// - Merges multiple slashes into one.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use actix_web::{web, http, middleware, App, HttpResponse};
|
||||||
|
///
|
||||||
|
/// fn main() {
|
||||||
|
/// let app = App::new()
|
||||||
|
/// .wrap(middleware::NormalizePath)
|
||||||
|
/// .service(
|
||||||
|
/// web::resource("/test")
|
||||||
|
/// .route(web::get().to(|| HttpResponse::Ok()))
|
||||||
|
/// .route(web::method(http::Method::HEAD).to(|| HttpResponse::MethodNotAllowed()))
|
||||||
|
/// );
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
|
||||||
pub struct NormalizePath;
|
pub struct NormalizePath;
|
||||||
|
|
||||||
impl<S> Transform<S> for NormalizePath
|
impl<S, B> Transform<S> for NormalizePath
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = NormalizePathNormalization<S>;
|
type Transform = NormalizePathNormalization<S>;
|
||||||
|
@ -39,12 +55,13 @@ pub struct NormalizePathNormalization<S> {
|
||||||
merge_slash: Regex,
|
merge_slash: Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Service for NormalizePathNormalization<S>
|
impl<S, B> Service for NormalizePathNormalization<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = S::Future;
|
type Future = S::Future;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue