mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
deprecate builder if-x methods (#1760)
This commit is contained in:
parent
9963a5ef54
commit
4cb833616a
@ -7,6 +7,10 @@
|
|||||||
### Changed
|
### Changed
|
||||||
* Upgrade `base64` to `0.13`.
|
* Upgrade `base64` to `0.13`.
|
||||||
* Upgrade `pin-project` to `1.0`.
|
* 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
|
[#1754]: https://github.com/actix/actix-web/pull/1754
|
||||||
|
|
||||||
|
@ -554,8 +554,9 @@ impl ResponseBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method calls provided closure with builder reference if value is
|
/// This method calls provided closure with builder reference if value is `true`.
|
||||||
/// true.
|
#[doc(hidden)]
|
||||||
|
#[deprecated = "Use an if statement."]
|
||||||
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self
|
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut ResponseBuilder),
|
F: FnOnce(&mut ResponseBuilder),
|
||||||
@ -566,8 +567,9 @@ impl ResponseBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method calls provided closure with builder reference if value is
|
/// This method calls provided closure with builder reference if value is `Some`.
|
||||||
/// Some.
|
#[doc(hidden)]
|
||||||
|
#[deprecated = "Use an if-let construction."]
|
||||||
pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Self
|
pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Self
|
||||||
where
|
where
|
||||||
F: FnOnce(T, &mut ResponseBuilder),
|
F: FnOnce(T, &mut ResponseBuilder),
|
||||||
|
@ -3,11 +3,13 @@
|
|||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
### Changed
|
### Changed
|
||||||
* Upgrade `base64` to `0.13`.
|
* Upgrade `base64` to `0.13`.
|
||||||
|
* Deprecate `ClientRequest::{if_some, if_true}`. [#1760]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* Use `Accept-Encoding: identity` instead of `Accept-Encoding: br` when no compression feature is enabled [#1737]
|
* 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
|
[#1737]: https://github.com/actix/actix-web/pull/1737
|
||||||
|
[#1760]: https://github.com/actix/actix-web/pull/1760
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0 - 2020-09-11
|
## 2.0.0 - 2020-09-11
|
||||||
|
@ -354,8 +354,9 @@ impl ClientRequest {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method calls provided closure with builder reference if
|
/// This method calls provided closure with builder reference if value is `true`.
|
||||||
/// value is `true`.
|
#[doc(hidden)]
|
||||||
|
#[deprecated = "Use an if statement."]
|
||||||
pub fn if_true<F>(self, value: bool, f: F) -> Self
|
pub fn if_true<F>(self, value: bool, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: FnOnce(ClientRequest) -> ClientRequest,
|
F: FnOnce(ClientRequest) -> ClientRequest,
|
||||||
@ -367,8 +368,9 @@ impl ClientRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method calls provided closure with builder reference if
|
/// This method calls provided closure with builder reference if value is `Some`.
|
||||||
/// value is `Some`.
|
#[doc(hidden)]
|
||||||
|
#[deprecated = "Use an if-let construction."]
|
||||||
pub fn if_some<T, F>(self, value: Option<T>, f: F) -> Self
|
pub fn if_some<T, F>(self, value: Option<T>, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: FnOnce(T, ClientRequest) -> ClientRequest,
|
F: FnOnce(T, ClientRequest) -> ClientRequest,
|
||||||
@ -601,20 +603,27 @@ mod tests {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_basics() {
|
async fn test_basics() {
|
||||||
let mut req = Client::new()
|
let req = Client::new()
|
||||||
.put("/")
|
.put("/")
|
||||||
.version(Version::HTTP_2)
|
.version(Version::HTTP_2)
|
||||||
.set(header::Date(SystemTime::now().into()))
|
.set(header::Date(SystemTime::now().into()))
|
||||||
.content_type("plain/text")
|
.content_type("plain/text")
|
||||||
.if_true(true, |req| req.header(header::SERVER, "awc"))
|
.header(header::SERVER, "awc");
|
||||||
.if_true(false, |req| req.header(header::EXPECT, "awc"))
|
|
||||||
.if_some(Some("server"), |val, req| {
|
let req = if let Some(val) = Some("server") {
|
||||||
req.header(header::USER_AGENT, val)
|
req.header(header::USER_AGENT, val)
|
||||||
})
|
} else {
|
||||||
.if_some(Option::<&str>::None, |_, req| {
|
req
|
||||||
|
};
|
||||||
|
|
||||||
|
let req = if let Some(_val) = Option::<&str>::None {
|
||||||
req.header(header::ALLOW, "1")
|
req.header(header::ALLOW, "1")
|
||||||
})
|
} else {
|
||||||
.content_length(100);
|
req
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut req = req.content_length(100);
|
||||||
|
|
||||||
assert!(req.headers().contains_key(header::CONTENT_TYPE));
|
assert!(req.headers().contains_key(header::CONTENT_TYPE));
|
||||||
assert!(req.headers().contains_key(header::DATE));
|
assert!(req.headers().contains_key(header::DATE));
|
||||||
assert!(req.headers().contains_key(header::SERVER));
|
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::ALLOW));
|
||||||
assert!(!req.headers().contains_key(header::EXPECT));
|
assert!(!req.headers().contains_key(header::EXPECT));
|
||||||
assert_eq!(req.head.version, Version::HTTP_2);
|
assert_eq!(req.head.version, Version::HTTP_2);
|
||||||
|
|
||||||
let _ = req.headers_mut();
|
let _ = req.headers_mut();
|
||||||
let _ = req.send_body("");
|
let _ = req.send_body("");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user