Skip to content

Commit 3595307

Browse files
committed
update sec fn names
1 parent 86b6a75 commit 3595307

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/security/mod.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
//! HTTP Security Headers.
22
//!
3-
// //! ## Example
4-
// //!
5-
// //! ```
6-
// //! use http_types::Response;
7-
// //!
8-
// //! let mut res = Response::new(StatusCode::Ok);
9-
// //! http_types::security::default(&mut res);
3+
//! ## Example
4+
//!
5+
//! ```
6+
//! use http_types::Response;
7+
//!
8+
//! let mut res = Response::new(StatusCode::Ok);
9+
//! http_types::security::default(&mut res);
1010
// //! assert_eq!(res["X-Content-Type-Options"], "nosniff");
1111
// //! assert_eq!(res["X-XSS-Protection"], "1; mode=block");
12-
// //! ```
13-
use crate::headers::{HeaderName, Headers};
12+
//! ```
13+
14+
use crate::headers::{HeaderName, HeaderValue, Headers};
1415
pub use csp::{ContentSecurityPolicy, ReportTo, ReportToEndpoint, Source};
1516

1617
mod csp;
@@ -30,7 +31,7 @@ pub fn default(mut headers: impl AsMut<Headers>) {
3031
dns_prefetch_control(&mut headers);
3132
nosniff(&mut headers);
3233
frameguard(&mut headers, None);
33-
hide_powered_by(&mut headers);
34+
powered_by(&mut headers, None);
3435
hsts(&mut headers);
3536
xss_filter(&mut headers);
3637
}
@@ -100,10 +101,16 @@ pub fn frameguard(mut headers: impl AsMut<Headers>, guard: Option<FrameOptions>)
100101
// /// assert_eq!(headers.get("X-Powered-By"), None);
101102
// /// ```
102103
#[inline]
103-
pub fn hide_powered_by(mut headers: impl AsMut<Headers>) {
104-
headers
105-
.as_mut()
106-
.remove(&HeaderName::from_lowercase_str("X-Powered-By"));
104+
pub fn powered_by(mut headers: impl AsMut<Headers>, value: Option<HeaderValue>) {
105+
let name = HeaderName::from_lowercase_str("X-Powered-By");
106+
match value {
107+
Some(value) => {
108+
headers.as_mut().insert(name, value).unwrap();
109+
}
110+
None => {
111+
headers.as_mut().remove(&name);
112+
}
113+
};
107114
}
108115

109116
/// Sets the `Strict-Transport-Security` header to keep your users on `HTTPS`.

0 commit comments

Comments
 (0)