1
0
Fork 0
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:
Douman 2019-05-01 21:47:51 +03:00 committed by Nikolay Kim
parent 24bd5b1344
commit 87284f0951

View file

@ -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;