1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

deprecate App::data and App::data_factory (#2271)

This commit is contained in:
Rob Ede 2021-06-22 15:50:58 +01:00 committed by GitHub
parent 2d8530feb3
commit 12f7720309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 42 additions and 3 deletions

View File

@ -3,8 +3,10 @@
## Unreleased - 2021-xx-xx
### Changed
* Change compression algorithm features flags. [#2250]
* Deprecate `App::data` and `App::data_factory`. [#2271]
[#2250]: https://github.com/actix/actix-web/pull/2250
[#2271]: https://github.com/actix/actix-web/pull/2271
## 4.0.0-beta.7 - 2021-06-17

View File

@ -98,13 +98,18 @@ where
/// web::resource("/index.html").route(
/// web::get().to(index)));
/// ```
#[deprecated(since = "4.0.0", note = "Use `.app_data(Data::new(val))` instead.")]
pub fn data<U: 'static>(self, data: U) -> Self {
self.app_data(Data::new(data))
}
/// Set application data factory. This function is
/// similar to `.data()` but it accepts data factory. Data object get
/// constructed asynchronously during application initialization.
/// Add application data factory. This function is similar to `.data()` but it accepts a
/// "data factory". Data values are constructed asynchronously during application
/// initialization, before the server starts accepting requests.
#[deprecated(
since = "4.0.0",
note = "Construct data value before starting server and use `.app_data(Data::new(val))` instead."
)]
pub fn data_factory<F, Out, D, E>(mut self, data: F) -> Self
where
F: Fn() -> Out + 'static,
@ -518,6 +523,8 @@ mod tests {
assert_eq!(resp.status(), StatusCode::CREATED);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_data_factory() {
let srv = init_service(
@ -541,6 +548,8 @@ mod tests {
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_data_factory_errors() {
let srv = try_init_service(

View File

@ -349,6 +349,8 @@ mod tests {
}
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_drop_data() {
let data = Arc::new(AtomicBool::new(false));

View File

@ -154,6 +154,8 @@ mod tests {
web, App, HttpResponse,
};
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_data_extractor() {
let srv = init_service(App::new().data("TEST".to_string()).service(
@ -221,6 +223,8 @@ mod tests {
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_route_data_extractor() {
let srv = init_service(
@ -250,6 +254,8 @@ mod tests {
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_override_data() {
let srv =

View File

@ -711,6 +711,8 @@ mod tests {
assert_eq!(body, Bytes::from_static(b"1"));
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_extensions_dropped() {
struct Tracker {

View File

@ -196,6 +196,7 @@ where
/// ));
/// }
/// ```
#[deprecated(since = "4.0.0", note = "Use `.app_data(Data::new(val))` instead.")]
pub fn data<U: 'static>(self, data: U) -> Self {
self.app_data(Data::new(data))
}
@ -694,6 +695,8 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_data() {
let srv = init_service(
@ -726,6 +729,8 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_data_default_service() {
let srv = init_service(

View File

@ -146,6 +146,7 @@ where
/// );
/// }
/// ```
#[deprecated(since = "4.0.0", note = "Use `.app_data(Data::new(val))` instead.")]
pub fn data<U: 'static>(self, data: U) -> Self {
self.app_data(Data::new(data))
}
@ -990,6 +991,8 @@ mod tests {
);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_override_data() {
let srv = init_service(App::new().data(1usize).service(
@ -1008,6 +1011,8 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_override_data_default_service() {
let srv = init_service(App::new().data(1usize).service(

View File

@ -649,6 +649,8 @@ mod tests {
assert_eq!(resp.status(), http::StatusCode::NOT_FOUND);
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_service_data() {
let srv =

View File

@ -839,6 +839,8 @@ mod tests {
assert!(res.status().is_success());
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_server_data() {
async fn handler(data: web::Data<usize>) -> impl Responder {

View File

@ -398,6 +398,8 @@ mod tests {
assert!(cfg.check_mimetype(&req).is_ok());
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_config_recall_locations() {
async fn bytes_handler(_: Bytes) -> impl Responder {

View File

@ -1028,6 +1028,8 @@ async fn test_normalize() {
assert!(response.status().is_success());
}
// allow deprecated App::data
#[allow(deprecated)]
#[actix_rt::test]
async fn test_data_drop() {
use std::sync::{