1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-30 10:42:55 +01:00

deprecate builder if-x methods (#1760)

This commit is contained in:
Rob Ede 2020-10-30 02:10:05 +00:00 committed by GitHub
parent 9963a5ef54
commit 4cb833616a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 18 deletions

View File

@ -7,6 +7,10 @@
### Changed
* Upgrade `base64` to `0.13`.
* Upgrade `pin-project` to `1.0`.
* Deprecate `ResponseBuilder::{if_some, if_true}`. [#1760]
[#1760]: https://github.com/actix/actix-web/pull/1760
[#1754]: https://github.com/actix/actix-web/pull/1754

View File

@ -554,8 +554,9 @@ impl ResponseBuilder {
self
}
/// This method calls provided closure with builder reference if value is
/// true.
/// This method calls provided closure with builder reference if value is `true`.
#[doc(hidden)]
#[deprecated = "Use an if statement."]
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self
where
F: FnOnce(&mut ResponseBuilder),
@ -566,8 +567,9 @@ impl ResponseBuilder {
self
}
/// This method calls provided closure with builder reference if value is
/// Some.
/// This method calls provided closure with builder reference if value is `Some`.
#[doc(hidden)]
#[deprecated = "Use an if-let construction."]
pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Self
where
F: FnOnce(T, &mut ResponseBuilder),

View File

@ -3,11 +3,13 @@
## Unreleased - 2020-xx-xx
### Changed
* Upgrade `base64` to `0.13`.
* Deprecate `ClientRequest::{if_some, if_true}`. [#1760]
### Fixed
* Use `Accept-Encoding: identity` instead of `Accept-Encoding: br` when no compression feature is enabled [#1737]
[#1737]: https://github.com/actix/actix-web/pull/1737
[#1760]: https://github.com/actix/actix-web/pull/1760
## 2.0.0 - 2020-09-11

View File

@ -354,8 +354,9 @@ impl ClientRequest {
self
}
/// This method calls provided closure with builder reference if
/// value is `true`.
/// This method calls provided closure with builder reference if value is `true`.
#[doc(hidden)]
#[deprecated = "Use an if statement."]
pub fn if_true<F>(self, value: bool, f: F) -> Self
where
F: FnOnce(ClientRequest) -> ClientRequest,
@ -367,8 +368,9 @@ impl ClientRequest {
}
}
/// This method calls provided closure with builder reference if
/// value is `Some`.
/// This method calls provided closure with builder reference if value is `Some`.
#[doc(hidden)]
#[deprecated = "Use an if-let construction."]
pub fn if_some<T, F>(self, value: Option<T>, f: F) -> Self
where
F: FnOnce(T, ClientRequest) -> ClientRequest,
@ -601,20 +603,27 @@ mod tests {
#[actix_rt::test]
async fn test_basics() {
let mut req = Client::new()
let req = Client::new()
.put("/")
.version(Version::HTTP_2)
.set(header::Date(SystemTime::now().into()))
.content_type("plain/text")
.if_true(true, |req| req.header(header::SERVER, "awc"))
.if_true(false, |req| req.header(header::EXPECT, "awc"))
.if_some(Some("server"), |val, req| {
.header(header::SERVER, "awc");
let req = if let Some(val) = Some("server") {
req.header(header::USER_AGENT, val)
})
.if_some(Option::<&str>::None, |_, req| {
} else {
req
};
let req = if let Some(_val) = Option::<&str>::None {
req.header(header::ALLOW, "1")
})
.content_length(100);
} else {
req
};
let mut req = req.content_length(100);
assert!(req.headers().contains_key(header::CONTENT_TYPE));
assert!(req.headers().contains_key(header::DATE));
assert!(req.headers().contains_key(header::SERVER));
@ -622,6 +631,7 @@ mod tests {
assert!(!req.headers().contains_key(header::ALLOW));
assert!(!req.headers().contains_key(header::EXPECT));
assert_eq!(req.head.version, Version::HTTP_2);
let _ = req.headers_mut();
let _ = req.send_body("");
}