mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
added clarification to docs regarding middleware processing sequence, added delete method to TestRequest (#799)
* added clarification to docs regarding middleware processing sequnce * added delete method to TestRequest, doc, and test
This commit is contained in:
parent
8db6b48a76
commit
b51b5b763c
10
src/app.rs
10
src/app.rs
@ -301,7 +301,15 @@ where
|
|||||||
/// lifecycle (request -> response), modifying request/response as
|
/// lifecycle (request -> response), modifying request/response as
|
||||||
/// necessary, across all requests managed by the *Application*.
|
/// necessary, across all requests managed by the *Application*.
|
||||||
///
|
///
|
||||||
/// Use middleware when you need to read or modify *every* request or response in some way.
|
/// Use middleware when you need to read or modify *every* request or
|
||||||
|
/// response in some way.
|
||||||
|
///
|
||||||
|
/// Notice that the keyword for registering middleware is `wrap`. As you
|
||||||
|
/// register middleware using `wrap` in the App builder, imagine wrapping
|
||||||
|
/// layers around an inner App. The first middleware layer exposed to a
|
||||||
|
/// Request is the outermost layer-- the *last* registered in
|
||||||
|
/// the builder chain. Consequently, the *first* middleware registered
|
||||||
|
/// in the builder chain is the *last* to execute during request processing.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use actix_service::Service;
|
/// use actix_service::Service;
|
||||||
|
14
src/test.rs
14
src/test.rs
@ -386,6 +386,11 @@ impl TestRequest {
|
|||||||
TestRequest::default().method(Method::PATCH)
|
TestRequest::default().method(Method::PATCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create TestRequest and set method to `Method::DELETE`
|
||||||
|
pub fn delete() -> TestRequest {
|
||||||
|
TestRequest::default().method(Method::DELETE)
|
||||||
|
}
|
||||||
|
|
||||||
/// Set HTTP version of this request
|
/// Set HTTP version of this request
|
||||||
pub fn version(mut self, ver: Version) -> Self {
|
pub fn version(mut self, ver: Version) -> Self {
|
||||||
self.req.version(ver);
|
self.req.version(ver);
|
||||||
@ -549,7 +554,8 @@ mod tests {
|
|||||||
App::new().service(
|
App::new().service(
|
||||||
web::resource("/index.html")
|
web::resource("/index.html")
|
||||||
.route(web::put().to(|| HttpResponse::Ok().body("put!")))
|
.route(web::put().to(|| HttpResponse::Ok().body("put!")))
|
||||||
.route(web::patch().to(|| HttpResponse::Ok().body("patch!"))),
|
.route(web::patch().to(|| HttpResponse::Ok().body("patch!")))
|
||||||
|
.route(web::delete().to(|| HttpResponse::Ok().body("delete!")))
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -568,6 +574,12 @@ mod tests {
|
|||||||
|
|
||||||
let result = read_response(&mut app, patch_req);
|
let result = read_response(&mut app, patch_req);
|
||||||
assert_eq!(result, Bytes::from_static(b"patch!"));
|
assert_eq!(result, Bytes::from_static(b"patch!"));
|
||||||
|
|
||||||
|
let delete_req = TestRequest::delete()
|
||||||
|
.uri("/index.html")
|
||||||
|
.to_request();
|
||||||
|
let result = read_response(&mut app, delete_req);
|
||||||
|
assert_eq!(result, Bytes::from_static(b"delete!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user