mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
remove Deref
This commit is contained in:
parent
e282ef7925
commit
bca31eb7ad
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
* Renamed `TestRequest::to_response()` to `TestRequest::to_srv_response()`
|
* Renamed `TestRequest::to_response()` to `TestRequest::to_srv_response()`
|
||||||
|
|
||||||
|
* Removed `Deref` impls
|
||||||
|
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -116,4 +116,7 @@ codegen-units = 1
|
|||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
actix = { git = "https://github.com/actix/actix.git" }
|
actix = { git = "https://github.com/actix/actix.git" }
|
||||||
|
actix-web = { path = "." }
|
||||||
actix-http = { path = "actix-http" }
|
actix-http = { path = "actix-http" }
|
||||||
|
actix-http-test = { path = "test-server" }
|
||||||
|
awc = { path = "awc" }
|
||||||
|
@ -35,10 +35,10 @@ fn test_h1_v2() {
|
|||||||
.finish(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
|
.finish(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
});
|
});
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
let request = srv.get().header("x-test", "111").send();
|
let request = srv.get("/").header("x-test", "111").send();
|
||||||
let response = srv.block_on(request).unwrap();
|
let response = srv.block_on(request).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ fn test_h1_v2() {
|
|||||||
let bytes = srv.load_body(response).unwrap();
|
let bytes = srv.load_body(response).unwrap();
|
||||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||||
|
|
||||||
let response = srv.block_on(srv.post().send()).unwrap();
|
let response = srv.block_on(srv.post("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -61,7 +61,9 @@ fn test_connection_close() {
|
|||||||
.finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
.finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
});
|
});
|
||||||
let response = srv.block_on(srv.get().close_connection().send()).unwrap();
|
let response = srv
|
||||||
|
.block_on(srv.get("/").close_connection().send())
|
||||||
|
.unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ fn test_h1() {
|
|||||||
.h1(|_| future::ok::<_, ()>(Response::Ok().finish()))
|
.h1(|_| future::ok::<_, ()>(Response::Ok().finish()))
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ fn test_h1_2() {
|
|||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ fn test_h2() -> std::io::Result<()> {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ fn test_h2_1() -> std::io::Result<()> {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ fn test_h2_body() -> std::io::Result<()> {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send_body(data.clone())).unwrap();
|
let response = srv.block_on(srv.sget("/").send_body(data.clone())).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
let body = srv.load_body(response).unwrap();
|
let body = srv.load_body(response).unwrap();
|
||||||
@ -437,7 +437,7 @@ fn test_h1_headers() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -482,7 +482,7 @@ fn test_h2_headers() {
|
|||||||
}).map_err(|_| ()))
|
}).map_err(|_| ()))
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -518,7 +518,7 @@ fn test_h1_body() {
|
|||||||
HttpService::build().h1(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
|
HttpService::build().h1(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -541,7 +541,7 @@ fn test_h2_body2() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -555,7 +555,7 @@ fn test_h1_head_empty() {
|
|||||||
HttpService::build().h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
HttpService::build().h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.head().send()).unwrap();
|
let response = srv.block_on(srv.head("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -586,7 +586,7 @@ fn test_h2_head_empty() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.shead().send()).unwrap();
|
let response = srv.block_on(srv.shead("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
assert_eq!(response.version(), http::Version::HTTP_2);
|
assert_eq!(response.version(), http::Version::HTTP_2);
|
||||||
|
|
||||||
@ -611,7 +611,7 @@ fn test_h1_head_binary() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.head().send()).unwrap();
|
let response = srv.block_on(srv.head("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -646,7 +646,7 @@ fn test_h2_head_binary() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.shead().send()).unwrap();
|
let response = srv.block_on(srv.shead("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -668,7 +668,7 @@ fn test_h1_head_binary2() {
|
|||||||
HttpService::build().h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
HttpService::build().h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.head().send()).unwrap();
|
let response = srv.block_on(srv.head("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -695,7 +695,7 @@ fn test_h2_head_binary2() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.shead().send()).unwrap();
|
let response = srv.block_on(srv.shead("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -719,7 +719,7 @@ fn test_h1_body_length() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -747,7 +747,7 @@ fn test_h2_body_length() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -768,7 +768,7 @@ fn test_h1_body_chunked_explicit() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
response
|
response
|
||||||
@ -810,7 +810,7 @@ fn test_h2_body_chunked_explicit() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
assert!(!response.headers().contains_key(header::TRANSFER_ENCODING));
|
assert!(!response.headers().contains_key(header::TRANSFER_ENCODING));
|
||||||
|
|
||||||
@ -830,7 +830,7 @@ fn test_h1_body_chunked_implicit() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
response
|
response
|
||||||
@ -862,7 +862,7 @@ fn test_h1_response_http_error_handling() {
|
|||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -895,7 +895,7 @@ fn test_h2_response_http_error_handling() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -910,7 +910,7 @@ fn test_h1_service_error() {
|
|||||||
.h1(|_| Err::<Response, Error>(error::ErrorBadRequest("error")))
|
.h1(|_| Err::<Response, Error>(error::ErrorBadRequest("error")))
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.get().send()).unwrap();
|
let response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -934,7 +934,7 @@ fn test_h2_service_error() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
let response = srv.block_on(srv.sget("/").send()).unwrap();
|
||||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
|
@ -83,7 +83,7 @@ impl<S> ClientResponse<S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Returns Request's headers.
|
/// Returns request's headers.
|
||||||
pub fn headers(&self) -> &HeaderMap {
|
pub fn headers(&self) -> &HeaderMap {
|
||||||
&self.head().headers
|
&self.head().headers
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ fn test_simple() {
|
|||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv.get().header("x-test", "111").send();
|
let request = srv.get("/").header("x-test", "111").send();
|
||||||
let response = srv.block_on(request).unwrap();
|
let response = srv.block_on(request).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ fn test_simple() {
|
|||||||
let bytes = srv.block_on(response.body()).unwrap();
|
let bytes = srv.block_on(response.body()).unwrap();
|
||||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||||
|
|
||||||
let response = srv.block_on(srv.post().send()).unwrap();
|
let response = srv.block_on(srv.post("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -114,7 +114,7 @@ fn test_timeout_override() {
|
|||||||
// let mut srv =
|
// let mut srv =
|
||||||
// test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
// test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
||||||
|
|
||||||
// let request = srv.get().header("Connection", "close").finish().unwrap();
|
// let request = srv.get("/").header("Connection", "close").finish().unwrap();
|
||||||
// let response = srv.execute(request.send()).unwrap();
|
// let response = srv.execute(request.send()).unwrap();
|
||||||
// assert!(response.status().is_success());
|
// assert!(response.status().is_success());
|
||||||
// }
|
// }
|
||||||
@ -128,7 +128,7 @@ fn test_timeout_override() {
|
|||||||
// })
|
// })
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// let request = srv.get().uri(srv.url("/?qp=5").as_str()).finish().unwrap();
|
// let request = srv.get("/").uri(srv.url("/?qp=5").as_str()).finish().unwrap();
|
||||||
|
|
||||||
// let response = srv.execute(request.send()).unwrap();
|
// let response = srv.execute(request.send()).unwrap();
|
||||||
// assert!(response.status().is_success());
|
// assert!(response.status().is_success());
|
||||||
@ -139,7 +139,7 @@ fn test_timeout_override() {
|
|||||||
// let mut srv =
|
// let mut srv =
|
||||||
// test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
// test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
||||||
|
|
||||||
// let request = srv.get().disable_decompress().finish().unwrap();
|
// let request = srv.get("/").disable_decompress().finish().unwrap();
|
||||||
// let response = srv.execute(request.send()).unwrap();
|
// let response = srv.execute(request.send()).unwrap();
|
||||||
// assert!(response.status().is_success());
|
// assert!(response.status().is_success());
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ fn test_client_gzip_encoding() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// client request
|
// client request
|
||||||
let response = srv.block_on(srv.post().send()).unwrap();
|
let response = srv.block_on(srv.post("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -200,7 +200,7 @@ fn test_client_gzip_encoding_large() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// client request
|
// client request
|
||||||
let response = srv.block_on(srv.post().send()).unwrap();
|
let response = srv.block_on(srv.post("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -229,7 +229,7 @@ fn test_client_gzip_encoding_large_random() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// client request
|
// client request
|
||||||
let response = srv.block_on(srv.post().send_body(data.clone())).unwrap();
|
let response = srv.block_on(srv.post("/").send_body(data.clone())).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -253,7 +253,7 @@ fn test_client_brotli_encoding() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// client request
|
// client request
|
||||||
let response = srv.block_on(srv.post().send_body(STR)).unwrap();
|
let response = srv.block_on(srv.post("/").send_body(STR)).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -375,7 +375,7 @@ fn test_client_brotli_encoding() {
|
|||||||
|
|
||||||
// let body = once(Ok(Bytes::from_static(STR.as_ref())));
|
// let body = once(Ok(Bytes::from_static(STR.as_ref())));
|
||||||
|
|
||||||
// let request = srv.get().body(Body::Streaming(Box::new(body))).unwrap();
|
// let request = srv.get("/").body(Body::Streaming(Box::new(body))).unwrap();
|
||||||
// let response = srv.execute(request.send()).unwrap();
|
// let response = srv.execute(request.send()).unwrap();
|
||||||
// assert!(response.status().is_success());
|
// assert!(response.status().is_success());
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ fn test_client_brotli_encoding() {
|
|||||||
// })
|
// })
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// let request = srv.get().finish().unwrap();
|
// let request = srv.get("/").finish().unwrap();
|
||||||
// let response = srv.execute(request.send()).unwrap();
|
// let response = srv.execute(request.send()).unwrap();
|
||||||
// assert!(response.status().is_success());
|
// assert!(response.status().is_success());
|
||||||
|
|
||||||
@ -459,7 +459,7 @@ fn test_client_cookie_handling() {
|
|||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv.get().cookie(cookie1.clone()).cookie(cookie2.clone());
|
let request = srv.get("/").cookie(cookie1.clone()).cookie(cookie2.clone());
|
||||||
let response = srv.block_on(request.send()).unwrap();
|
let response = srv.block_on(request.send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
let c1 = response.cookie("cookie1").expect("Missing cookie1");
|
let c1 = response.cookie("cookie1").expect("Missing cookie1");
|
||||||
@ -472,7 +472,7 @@ fn test_client_cookie_handling() {
|
|||||||
// fn test_default_headers() {
|
// fn test_default_headers() {
|
||||||
// let srv = test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
// let srv = test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
||||||
|
|
||||||
// let request = srv.get().finish().unwrap();
|
// let request = srv.get("/").finish().unwrap();
|
||||||
// let repr = format!("{:?}", request);
|
// let repr = format!("{:?}", request);
|
||||||
// assert!(repr.contains("\"accept-encoding\": \"gzip, deflate\""));
|
// assert!(repr.contains("\"accept-encoding\": \"gzip, deflate\""));
|
||||||
// assert!(repr.contains(concat!(
|
// assert!(repr.contains(concat!(
|
||||||
@ -482,7 +482,7 @@ fn test_client_cookie_handling() {
|
|||||||
// )));
|
// )));
|
||||||
|
|
||||||
// let request_override = srv
|
// let request_override = srv
|
||||||
// .get()
|
// .get("/")
|
||||||
// .header("User-Agent", "test")
|
// .header("User-Agent", "test")
|
||||||
// .header("Accept-Encoding", "over_test")
|
// .header("Accept-Encoding", "over_test")
|
||||||
// .finish()
|
// .finish()
|
||||||
@ -551,7 +551,7 @@ fn client_basic_auth() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// set authorization header to Basic <base64 encoded username:password>
|
// set authorization header to Basic <base64 encoded username:password>
|
||||||
let request = srv.get().basic_auth("username", Some("password"));
|
let request = srv.get("/").basic_auth("username", Some("password"));
|
||||||
let response = srv.block_on(request.send()).unwrap();
|
let response = srv.block_on(request.send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
}
|
}
|
||||||
@ -579,7 +579,7 @@ fn client_bearer_auth() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// set authorization header to Bearer <token>
|
// set authorization header to Bearer <token>
|
||||||
let request = srv.get().bearer_auth("someS3cr3tAutht0k3n");
|
let request = srv.get("/").bearer_auth("someS3cr3tAutht0k3n");
|
||||||
let response = srv.block_on(request.send()).unwrap();
|
let response = srv.block_on(request.send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ impl<T: 'static, P> FromRequest<P> for Data<T> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||||
if let Some(st) = req.config().extensions().get::<Data<T>>() {
|
if let Some(st) = req.request().config().extensions().get::<Data<T>>() {
|
||||||
Ok(st.clone())
|
Ok(st.clone())
|
||||||
} else {
|
} else {
|
||||||
Err(ErrorInternalServerError(
|
Err(ErrorInternalServerError(
|
||||||
|
63
src/guard.rs
63
src/guard.rs
@ -73,6 +73,15 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<F> Guard for F
|
||||||
|
where
|
||||||
|
F: Fn(&RequestHead) -> bool,
|
||||||
|
{
|
||||||
|
fn check(&self, head: &RequestHead) -> bool {
|
||||||
|
(self)(head)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return guard that matches if any of supplied guards.
|
/// Return guard that matches if any of supplied guards.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
@ -300,13 +309,13 @@ mod tests {
|
|||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
let pred = Header("transfer-encoding", "chunked");
|
let pred = Header("transfer-encoding", "chunked");
|
||||||
assert!(pred.check(&req));
|
assert!(pred.check(req.head()));
|
||||||
|
|
||||||
let pred = Header("transfer-encoding", "other");
|
let pred = Header("transfer-encoding", "other");
|
||||||
assert!(!pred.check(&req));
|
assert!(!pred.check(req.head()));
|
||||||
|
|
||||||
let pred = Header("content-type", "other");
|
let pred = Header("content-type", "other");
|
||||||
assert!(!pred.check(&req));
|
assert!(!pred.check(req.head()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
@ -332,50 +341,50 @@ mod tests {
|
|||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
assert!(Get().check(&req));
|
assert!(Get().check(req.head()));
|
||||||
assert!(!Get().check(&req2));
|
assert!(!Get().check(req2.head()));
|
||||||
assert!(Post().check(&req2));
|
assert!(Post().check(req2.head()));
|
||||||
assert!(!Post().check(&req));
|
assert!(!Post().check(req.head()));
|
||||||
|
|
||||||
let r = TestRequest::default().method(Method::PUT).to_http_request();
|
let r = TestRequest::default().method(Method::PUT).to_http_request();
|
||||||
assert!(Put().check(&r));
|
assert!(Put().check(r.head()));
|
||||||
assert!(!Put().check(&req));
|
assert!(!Put().check(req.head()));
|
||||||
|
|
||||||
let r = TestRequest::default()
|
let r = TestRequest::default()
|
||||||
.method(Method::DELETE)
|
.method(Method::DELETE)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert!(Delete().check(&r));
|
assert!(Delete().check(r.head()));
|
||||||
assert!(!Delete().check(&req));
|
assert!(!Delete().check(req.head()));
|
||||||
|
|
||||||
let r = TestRequest::default()
|
let r = TestRequest::default()
|
||||||
.method(Method::HEAD)
|
.method(Method::HEAD)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert!(Head().check(&r));
|
assert!(Head().check(r.head()));
|
||||||
assert!(!Head().check(&req));
|
assert!(!Head().check(req.head()));
|
||||||
|
|
||||||
let r = TestRequest::default()
|
let r = TestRequest::default()
|
||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert!(Options().check(&r));
|
assert!(Options().check(r.head()));
|
||||||
assert!(!Options().check(&req));
|
assert!(!Options().check(req.head()));
|
||||||
|
|
||||||
let r = TestRequest::default()
|
let r = TestRequest::default()
|
||||||
.method(Method::CONNECT)
|
.method(Method::CONNECT)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert!(Connect().check(&r));
|
assert!(Connect().check(r.head()));
|
||||||
assert!(!Connect().check(&req));
|
assert!(!Connect().check(req.head()));
|
||||||
|
|
||||||
let r = TestRequest::default()
|
let r = TestRequest::default()
|
||||||
.method(Method::PATCH)
|
.method(Method::PATCH)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert!(Patch().check(&r));
|
assert!(Patch().check(r.head()));
|
||||||
assert!(!Patch().check(&req));
|
assert!(!Patch().check(req.head()));
|
||||||
|
|
||||||
let r = TestRequest::default()
|
let r = TestRequest::default()
|
||||||
.method(Method::TRACE)
|
.method(Method::TRACE)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert!(Trace().check(&r));
|
assert!(Trace().check(r.head()));
|
||||||
assert!(!Trace().check(&req));
|
assert!(!Trace().check(req.head()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -384,13 +393,13 @@ mod tests {
|
|||||||
.method(Method::TRACE)
|
.method(Method::TRACE)
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
assert!(Not(Get()).check(&r));
|
assert!(Not(Get()).check(r.head()));
|
||||||
assert!(!Not(Trace()).check(&r));
|
assert!(!Not(Trace()).check(r.head()));
|
||||||
|
|
||||||
assert!(All(Trace()).and(Trace()).check(&r));
|
assert!(All(Trace()).and(Trace()).check(r.head()));
|
||||||
assert!(!All(Get()).and(Trace()).check(&r));
|
assert!(!All(Get()).and(Trace()).check(r.head()));
|
||||||
|
|
||||||
assert!(Any(Get()).or(Trace()).check(&r));
|
assert!(Any(Get()).or(Trace()).check(r.head()));
|
||||||
assert!(!Any(Get()).or(Get()).check(&r));
|
assert!(!Any(Get()).or(Get()).check(r.head()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ where
|
|||||||
|
|
||||||
fn call(&mut self, req: ServiceRequest<P>) -> Self::Future {
|
fn call(&mut self, req: ServiceRequest<P>) -> Self::Future {
|
||||||
// negotiate content-encoding
|
// negotiate content-encoding
|
||||||
let encoding = if let Some(val) = req.headers.get(ACCEPT_ENCODING) {
|
let encoding = if let Some(val) = req.headers().get(ACCEPT_ENCODING) {
|
||||||
if let Ok(enc) = val.to_str() {
|
if let Ok(enc) = val.to_str() {
|
||||||
AcceptEncoding::parse(enc, self.encoding)
|
AcceptEncoding::parse(enc, self.encoding)
|
||||||
} else {
|
} else {
|
||||||
@ -157,7 +157,7 @@ where
|
|||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
let resp = futures::try_ready!(self.fut.poll());
|
let resp = futures::try_ready!(self.fut.poll());
|
||||||
|
|
||||||
let enc = if let Some(enc) = resp.head().extensions().get::<Enc>() {
|
let enc = if let Some(enc) = resp.response().extensions().get::<Enc>() {
|
||||||
enc.0
|
enc.0
|
||||||
} else {
|
} else {
|
||||||
self.encoding
|
self.encoding
|
||||||
|
@ -51,7 +51,7 @@ use crate::error::{ResponseError, Result};
|
|||||||
use crate::http::header::{self, HeaderName, HeaderValue};
|
use crate::http::header::{self, HeaderName, HeaderValue};
|
||||||
use crate::http::{self, HttpTryFrom, Method, StatusCode, Uri};
|
use crate::http::{self, HttpTryFrom, Method, StatusCode, Uri};
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
use crate::{HttpMessage, HttpResponse};
|
use crate::HttpResponse;
|
||||||
|
|
||||||
/// A set of errors that can occur during processing CORS
|
/// A set of errors that can occur during processing CORS
|
||||||
#[derive(Debug, Display)]
|
#[derive(Debug, Display)]
|
||||||
@ -702,9 +702,9 @@ where
|
|||||||
if self.inner.preflight && Method::OPTIONS == *req.method() {
|
if self.inner.preflight && Method::OPTIONS == *req.method() {
|
||||||
if let Err(e) = self
|
if let Err(e) = self
|
||||||
.inner
|
.inner
|
||||||
.validate_origin(&req)
|
.validate_origin(req.head())
|
||||||
.and_then(|_| self.inner.validate_allowed_method(&req))
|
.and_then(|_| self.inner.validate_allowed_method(req.head()))
|
||||||
.and_then(|_| self.inner.validate_allowed_headers(&req))
|
.and_then(|_| self.inner.validate_allowed_headers(req.head()))
|
||||||
{
|
{
|
||||||
return Either::A(ok(req.error_response(e)));
|
return Either::A(ok(req.error_response(e)));
|
||||||
}
|
}
|
||||||
@ -739,7 +739,7 @@ where
|
|||||||
let _ = resp.header(header::ACCESS_CONTROL_ALLOW_HEADERS, headers);
|
let _ = resp.header(header::ACCESS_CONTROL_ALLOW_HEADERS, headers);
|
||||||
})
|
})
|
||||||
.if_some(
|
.if_some(
|
||||||
self.inner.access_control_allow_origin(&req),
|
self.inner.access_control_allow_origin(req.head()),
|
||||||
|origin, resp| {
|
|origin, resp| {
|
||||||
let _ = resp.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin);
|
let _ = resp.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin);
|
||||||
},
|
},
|
||||||
@ -762,7 +762,7 @@ where
|
|||||||
Either::A(ok(req.into_response(res)))
|
Either::A(ok(req.into_response(res)))
|
||||||
} else if req.headers().contains_key(header::ORIGIN) {
|
} else if req.headers().contains_key(header::ORIGIN) {
|
||||||
// Only check requests with a origin header.
|
// Only check requests with a origin header.
|
||||||
if let Err(e) = self.inner.validate_origin(&req) {
|
if let Err(e) = self.inner.validate_origin(req.head()) {
|
||||||
return Either::A(ok(req.error_response(e)));
|
return Either::A(ok(req.error_response(e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,7 +771,7 @@ where
|
|||||||
Either::B(Either::B(Box::new(self.service.call(req).and_then(
|
Either::B(Either::B(Box::new(self.service.call(req).and_then(
|
||||||
move |mut res| {
|
move |mut res| {
|
||||||
if let Some(origin) =
|
if let Some(origin) =
|
||||||
inner.access_control_allow_origin(&res.request())
|
inner.access_control_allow_origin(res.request().head())
|
||||||
{
|
{
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin.clone());
|
.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin.clone());
|
||||||
@ -869,8 +869,8 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
assert!(cors.inner.validate_allowed_method(&req).is_err());
|
assert!(cors.inner.validate_allowed_method(req.head()).is_err());
|
||||||
assert!(cors.inner.validate_allowed_headers(&req).is_err());
|
assert!(cors.inner.validate_allowed_headers(req.head()).is_err());
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_success(&mut cors, req);
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
|
|
||||||
@ -879,8 +879,8 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
assert!(cors.inner.validate_allowed_method(&req).is_err());
|
assert!(cors.inner.validate_allowed_method(req.head()).is_err());
|
||||||
assert!(cors.inner.validate_allowed_headers(&req).is_err());
|
assert!(cors.inner.validate_allowed_headers(req.head()).is_err());
|
||||||
|
|
||||||
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
||||||
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "POST")
|
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "POST")
|
||||||
@ -961,9 +961,9 @@ mod tests {
|
|||||||
let req = TestRequest::with_header("Origin", "https://www.unknown.com")
|
let req = TestRequest::with_header("Origin", "https://www.unknown.com")
|
||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
cors.inner.validate_origin(&req).unwrap();
|
cors.inner.validate_origin(req.head()).unwrap();
|
||||||
cors.inner.validate_allowed_method(&req).unwrap();
|
cors.inner.validate_allowed_method(req.head()).unwrap();
|
||||||
cors.inner.validate_allowed_headers(&req).unwrap();
|
cors.inner.validate_allowed_headers(req.head()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -10,7 +10,6 @@ use futures::{Async, Poll, Stream};
|
|||||||
use crate::dev::Payload;
|
use crate::dev::Payload;
|
||||||
use crate::error::{Error, PayloadError};
|
use crate::error::{Error, PayloadError};
|
||||||
use crate::service::ServiceRequest;
|
use crate::service::ServiceRequest;
|
||||||
use crate::HttpMessage;
|
|
||||||
|
|
||||||
/// `Middleware` for decompressing request's payload.
|
/// `Middleware` for decompressing request's payload.
|
||||||
/// `Decompress` middleware must be added with `App::chain()` method.
|
/// `Decompress` middleware must be added with `App::chain()` method.
|
||||||
|
@ -148,7 +148,7 @@ impl<P> FromRequest<P> for Identity {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||||
Ok(Identity(req.clone()))
|
Ok(Identity(req.request().clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,7 +507,7 @@ mod tests {
|
|||||||
let resp =
|
let resp =
|
||||||
test::call_success(&mut srv, TestRequest::with_uri("/login").to_request());
|
test::call_success(&mut srv, TestRequest::with_uri("/login").to_request());
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
let c = resp.cookies().next().unwrap().to_owned();
|
let c = resp.response().cookies().next().unwrap().to_owned();
|
||||||
|
|
||||||
let resp = test::call_success(
|
let resp = test::call_success(
|
||||||
&mut srv,
|
&mut srv,
|
||||||
|
@ -15,7 +15,7 @@ use time;
|
|||||||
use crate::dev::{BodySize, MessageBody, ResponseBody};
|
use crate::dev::{BodySize, MessageBody, ResponseBody};
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
use crate::{HttpMessage, HttpResponse};
|
use crate::HttpResponse;
|
||||||
|
|
||||||
/// `Middleware` for logging request and response info to the terminal.
|
/// `Middleware` for logging request and response info to the terminal.
|
||||||
///
|
///
|
||||||
@ -201,7 +201,7 @@ where
|
|||||||
|
|
||||||
if let Some(ref mut format) = self.format {
|
if let Some(ref mut format) = self.format {
|
||||||
for unit in &mut format.0 {
|
for unit in &mut format.0 {
|
||||||
unit.render_response(&res);
|
unit.render_response(res.response());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::cell::{Ref, RefMut};
|
use std::cell::{Ref, RefMut};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::Deref;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use actix_http::http::{HeaderMap, Method, Uri, Version};
|
use actix_http::http::{HeaderMap, Method, Uri, Version};
|
||||||
@ -66,6 +65,12 @@ impl HttpRequest {
|
|||||||
self.head().version
|
self.head().version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Returns request's headers.
|
||||||
|
pub fn headers(&self) -> &HeaderMap {
|
||||||
|
&self.head().headers
|
||||||
|
}
|
||||||
|
|
||||||
/// The target path of this Request.
|
/// The target path of this Request.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn path(&self) -> &str {
|
pub fn path(&self) -> &str {
|
||||||
@ -111,6 +116,18 @@ impl HttpRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Request extensions
|
||||||
|
#[inline]
|
||||||
|
pub fn extensions(&self) -> Ref<Extensions> {
|
||||||
|
self.head().extensions()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mutable reference to a the request's extensions
|
||||||
|
#[inline]
|
||||||
|
pub fn extensions_mut(&self) -> RefMut<Extensions> {
|
||||||
|
self.head().extensions_mut()
|
||||||
|
}
|
||||||
|
|
||||||
/// Generate url for named resource
|
/// Generate url for named resource
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
@ -154,15 +171,7 @@ impl HttpRequest {
|
|||||||
/// Get *ConnectionInfo* for the current request.
|
/// Get *ConnectionInfo* for the current request.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn connection_info(&self) -> Ref<ConnectionInfo> {
|
pub fn connection_info(&self) -> Ref<ConnectionInfo> {
|
||||||
ConnectionInfo::get(&*self, &*self.config())
|
ConnectionInfo::get(self.head(), &*self.config())
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for HttpRequest {
|
|
||||||
type Target = RequestHead;
|
|
||||||
|
|
||||||
fn deref(&self) -> &RequestHead {
|
|
||||||
self.head()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +228,7 @@ impl<P> FromRequest<P> for HttpRequest {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||||
Ok(req.clone())
|
Ok(req.request().clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ pub(crate) mod tests {
|
|||||||
let req = TestRequest::with_uri("/some").to_request();
|
let req = TestRequest::with_uri("/some").to_request();
|
||||||
let resp = TestRequest::block_on(srv.call(req)).unwrap();
|
let resp = TestRequest::block_on(srv.call(req)).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
match resp.body() {
|
match resp.response().body() {
|
||||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||||
let bytes: Bytes = b.clone().into();
|
let bytes: Bytes = b.clone().into();
|
||||||
assert_eq!(bytes, Bytes::from_static(b"some"));
|
assert_eq!(bytes, Bytes::from_static(b"some"));
|
||||||
|
@ -693,7 +693,7 @@ mod tests {
|
|||||||
let resp = block_on(srv.call(req)).unwrap();
|
let resp = block_on(srv.call(req)).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
match resp.body() {
|
match resp.response().body() {
|
||||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||||
let bytes: Bytes = b.clone().into();
|
let bytes: Bytes = b.clone().into();
|
||||||
assert_eq!(bytes, Bytes::from_static(b"project: project1"));
|
assert_eq!(bytes, Bytes::from_static(b"project: project1"));
|
||||||
@ -799,7 +799,7 @@ mod tests {
|
|||||||
let resp = block_on(srv.call(req)).unwrap();
|
let resp = block_on(srv.call(req)).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::CREATED);
|
assert_eq!(resp.status(), StatusCode::CREATED);
|
||||||
|
|
||||||
match resp.body() {
|
match resp.response().body() {
|
||||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||||
let bytes: Bytes = b.clone().into();
|
let bytes: Bytes = b.clone().into();
|
||||||
assert_eq!(bytes, Bytes::from_static(b"project: project_1"));
|
assert_eq!(bytes, Bytes::from_static(b"project: project_1"));
|
||||||
@ -826,7 +826,7 @@ mod tests {
|
|||||||
let resp = block_on(srv.call(req)).unwrap();
|
let resp = block_on(srv.call(req)).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::CREATED);
|
assert_eq!(resp.status(), StatusCode::CREATED);
|
||||||
|
|
||||||
match resp.body() {
|
match resp.response().body() {
|
||||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||||
let bytes: Bytes = b.clone().into();
|
let bytes: Bytes = b.clone().into();
|
||||||
assert_eq!(bytes, Bytes::from_static(b"project: test - 1"));
|
assert_eq!(bytes, Bytes::from_static(b"project: test - 1"));
|
||||||
|
@ -4,7 +4,7 @@ use std::marker::PhantomData;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use actix_http::body::{Body, MessageBody, ResponseBody};
|
use actix_http::body::{Body, MessageBody, ResponseBody};
|
||||||
use actix_http::http::{HeaderMap, Method, Uri, Version};
|
use actix_http::http::{HeaderMap, Method, StatusCode, Uri, Version};
|
||||||
use actix_http::{
|
use actix_http::{
|
||||||
Error, Extensions, HttpMessage, Payload, PayloadStream, Request, RequestHead,
|
Error, Extensions, HttpMessage, Payload, PayloadStream, Request, RequestHead,
|
||||||
Response, ResponseHead,
|
Response, ResponseHead,
|
||||||
@ -123,7 +123,13 @@ impl<P> ServiceRequest<P> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Returns mutable Request's headers.
|
/// Returns request's headers.
|
||||||
|
pub fn headers(&self) -> &HeaderMap {
|
||||||
|
&self.head().headers
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Returns mutable request's headers.
|
||||||
pub fn headers_mut(&mut self) -> &mut HeaderMap {
|
pub fn headers_mut(&mut self) -> &mut HeaderMap {
|
||||||
&mut self.head_mut().headers
|
&mut self.head_mut().headers
|
||||||
}
|
}
|
||||||
@ -202,20 +208,6 @@ impl<P> HttpMessage for ServiceRequest<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> std::ops::Deref for ServiceRequest<P> {
|
|
||||||
type Target = RequestHead;
|
|
||||||
|
|
||||||
fn deref(&self) -> &RequestHead {
|
|
||||||
self.req.head()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> std::ops::DerefMut for ServiceRequest<P> {
|
|
||||||
fn deref_mut(&mut self) -> &mut RequestHead {
|
|
||||||
self.head_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> fmt::Debug for ServiceRequest<P> {
|
impl<P> fmt::Debug for ServiceRequest<P> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
writeln!(
|
writeln!(
|
||||||
@ -255,11 +247,19 @@ impl<P> ServiceFromRequest<P> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
/// Get reference to inner HttpRequest
|
||||||
|
pub fn request(&self) -> &HttpRequest {
|
||||||
|
&self.req
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Convert this request into a HttpRequest
|
||||||
pub fn into_request(self) -> HttpRequest {
|
pub fn into_request(self) -> HttpRequest {
|
||||||
self.req
|
self.req
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
/// Get match information for this request
|
||||||
pub fn match_info_mut(&mut self) -> &mut Path<Url> {
|
pub fn match_info_mut(&mut self) -> &mut Path<Url> {
|
||||||
&mut self.req.path
|
&mut self.req.path
|
||||||
}
|
}
|
||||||
@ -281,14 +281,6 @@ impl<P> ServiceFromRequest<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> std::ops::Deref for ServiceFromRequest<P> {
|
|
||||||
type Target = HttpRequest;
|
|
||||||
|
|
||||||
fn deref(&self) -> &HttpRequest {
|
|
||||||
&self.req
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> HttpMessage for ServiceFromRequest<P> {
|
impl<P> HttpMessage for ServiceFromRequest<P> {
|
||||||
type Stream = P;
|
type Stream = P;
|
||||||
|
|
||||||
@ -366,6 +358,24 @@ impl<B> ServiceResponse<B> {
|
|||||||
&mut self.response
|
&mut self.response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the response status code
|
||||||
|
#[inline]
|
||||||
|
pub fn status(&self) -> StatusCode {
|
||||||
|
self.response.status()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Returns response's headers.
|
||||||
|
pub fn headers(&self) -> &HeaderMap {
|
||||||
|
self.response.headers()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Returns mutable response's headers.
|
||||||
|
pub fn headers_mut(&mut self) -> &mut HeaderMap {
|
||||||
|
self.response.headers_mut()
|
||||||
|
}
|
||||||
|
|
||||||
/// Execute closure and in case of error convert it to response.
|
/// Execute closure and in case of error convert it to response.
|
||||||
pub fn checked_expr<F, E>(mut self, f: F) -> Self
|
pub fn checked_expr<F, E>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
@ -402,20 +412,6 @@ impl<B> ServiceResponse<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B> std::ops::Deref for ServiceResponse<B> {
|
|
||||||
type Target = Response<B>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Response<B> {
|
|
||||||
self.response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<B> std::ops::DerefMut for ServiceResponse<B> {
|
|
||||||
fn deref_mut(&mut self) -> &mut Response<B> {
|
|
||||||
self.response_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<B> Into<Response<B>> for ServiceResponse<B> {
|
impl<B> Into<Response<B>> for ServiceResponse<B> {
|
||||||
fn into(self) -> Response<B> {
|
fn into(self) -> Response<B> {
|
||||||
self.response
|
self.response
|
||||||
|
@ -80,7 +80,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||||
let req2 = req.clone();
|
let req2 = req.request().clone();
|
||||||
let (limit, err) = req
|
let (limit, err) = req
|
||||||
.route_data::<FormConfig>()
|
.route_data::<FormConfig>()
|
||||||
.map(|c| (c.limit, c.ehandler.clone()))
|
.map(|c| (c.limit, c.ehandler.clone()))
|
||||||
|
@ -174,7 +174,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||||
let req2 = req.clone();
|
let req2 = req.request().clone();
|
||||||
let (limit, err) = req
|
let (limit, err) = req
|
||||||
.route_data::<JsonConfig>()
|
.route_data::<JsonConfig>()
|
||||||
.map(|c| (c.limit, c.ehandler.clone()))
|
.map(|c| (c.limit, c.ehandler.clone()))
|
||||||
|
@ -170,7 +170,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||||
Self::extract(req).map_err(ErrorNotFound)
|
Self::extract(req.request()).map_err(ErrorNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||||
serde_urlencoded::from_str::<T>(req.query_string())
|
serde_urlencoded::from_str::<T>(req.request().query_string())
|
||||||
.map(|val| Ok(Query(val)))
|
.map(|val| Ok(Query(val)))
|
||||||
.unwrap_or_else(|e| Err(e.into()))
|
.unwrap_or_else(|e| Err(e.into()))
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ fn test_body() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -73,7 +73,7 @@ fn test_body_gzip() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut response = srv.block_on(srv.get().no_decompress().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").no_decompress().send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -111,7 +111,7 @@ fn test_body_encoding_override() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Builder
|
// Builder
|
||||||
let mut response = srv.block_on(srv.get().no_decompress().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").no_decompress().send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -161,7 +161,7 @@ fn test_body_gzip_large() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut response = srv.block_on(srv.get().no_decompress().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").no_decompress().send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -195,7 +195,7 @@ fn test_body_gzip_large_random() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut response = srv.block_on(srv.get().no_decompress().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").no_decompress().send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -224,7 +224,7 @@ fn test_body_chunked_implicit() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut response = srv.block_on(srv.get().no_decompress().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").no_decompress().send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
response.headers().get(TRANSFER_ENCODING).unwrap(),
|
response.headers().get(TRANSFER_ENCODING).unwrap(),
|
||||||
@ -258,7 +258,7 @@ fn test_body_br_streaming() {
|
|||||||
|
|
||||||
let mut response = srv
|
let mut response = srv
|
||||||
.block_on(
|
.block_on(
|
||||||
srv.get()
|
srv.get("/")
|
||||||
.header(ACCEPT_ENCODING, "br")
|
.header(ACCEPT_ENCODING, "br")
|
||||||
.no_decompress()
|
.no_decompress()
|
||||||
.send(),
|
.send(),
|
||||||
@ -284,7 +284,7 @@ fn test_head_binary() {
|
|||||||
)))
|
)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut response = srv.block_on(srv.head().send()).unwrap();
|
let mut response = srv.block_on(srv.head("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -310,7 +310,7 @@ fn test_no_chunking() {
|
|||||||
))))
|
))))
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
assert!(!response.headers().contains_key(TRANSFER_ENCODING));
|
assert!(!response.headers().contains_key(TRANSFER_ENCODING));
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ fn test_body_deflate() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// client request
|
// client request
|
||||||
let mut response = srv.block_on(srv.get().no_decompress().send()).unwrap();
|
let mut response = srv.block_on(srv.get("/").no_decompress().send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
// read response
|
// read response
|
||||||
@ -362,7 +362,7 @@ fn test_body_brotli() {
|
|||||||
// client request
|
// client request
|
||||||
let mut response = srv
|
let mut response = srv
|
||||||
.block_on(
|
.block_on(
|
||||||
srv.get()
|
srv.get("/")
|
||||||
.header(ACCEPT_ENCODING, "br")
|
.header(ACCEPT_ENCODING, "br")
|
||||||
.no_decompress()
|
.no_decompress()
|
||||||
.send(),
|
.send(),
|
||||||
@ -398,7 +398,7 @@ fn test_encoding() {
|
|||||||
let enc = e.finish().unwrap();
|
let enc = e.finish().unwrap();
|
||||||
|
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "gzip")
|
.header(CONTENT_ENCODING, "gzip")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -427,7 +427,7 @@ fn test_gzip_encoding() {
|
|||||||
let enc = e.finish().unwrap();
|
let enc = e.finish().unwrap();
|
||||||
|
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "gzip")
|
.header(CONTENT_ENCODING, "gzip")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -457,7 +457,7 @@ fn test_gzip_encoding_large() {
|
|||||||
let enc = e.finish().unwrap();
|
let enc = e.finish().unwrap();
|
||||||
|
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "gzip")
|
.header(CONTENT_ENCODING, "gzip")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -491,7 +491,7 @@ fn test_reading_gzip_encoding_large_random() {
|
|||||||
let enc = e.finish().unwrap();
|
let enc = e.finish().unwrap();
|
||||||
|
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "gzip")
|
.header(CONTENT_ENCODING, "gzip")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -521,7 +521,7 @@ fn test_reading_deflate_encoding() {
|
|||||||
|
|
||||||
// client request
|
// client request
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "deflate")
|
.header(CONTENT_ENCODING, "deflate")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -551,7 +551,7 @@ fn test_reading_deflate_encoding_large() {
|
|||||||
|
|
||||||
// client request
|
// client request
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "deflate")
|
.header(CONTENT_ENCODING, "deflate")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -585,7 +585,7 @@ fn test_reading_deflate_encoding_large_random() {
|
|||||||
|
|
||||||
// client request
|
// client request
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "deflate")
|
.header(CONTENT_ENCODING, "deflate")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -615,7 +615,7 @@ fn test_brotli_encoding() {
|
|||||||
|
|
||||||
// client request
|
// client request
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "br")
|
.header(CONTENT_ENCODING, "br")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -645,7 +645,7 @@ fn test_brotli_encoding_large() {
|
|||||||
|
|
||||||
// client request
|
// client request
|
||||||
let request = srv
|
let request = srv
|
||||||
.post()
|
.post("/")
|
||||||
.header(CONTENT_ENCODING, "br")
|
.header(CONTENT_ENCODING, "br")
|
||||||
.send_body(enc.clone());
|
.send_body(enc.clone());
|
||||||
let mut response = srv.block_on(request).unwrap();
|
let mut response = srv.block_on(request).unwrap();
|
||||||
@ -912,7 +912,7 @@ fn test_reading_deflate_encoding_large_random_ssl() {
|
|||||||
// .finish();
|
// .finish();
|
||||||
// let second_cookie = http::Cookie::new("second", "second_value");
|
// let second_cookie = http::Cookie::new("second", "second_value");
|
||||||
|
|
||||||
// let request = srv.get().finish().unwrap();
|
// let request = srv.get("/").finish().unwrap();
|
||||||
// let response = srv.execute(request.send()).unwrap();
|
// let response = srv.execute(request.send()).unwrap();
|
||||||
// assert!(response.status().is_success());
|
// assert!(response.status().is_success());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user