Skip to content

Commit

Permalink
Set strict transport security header (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 16, 2023
1 parent ab5af6c commit 7c8c93c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ impl Server {
.layer(SetResponseHeaderLayer::if_not_present(
header::CONTENT_SECURITY_POLICY,
HeaderValue::from_static("default-src 'self'"),
))
.layer(SetResponseHeaderLayer::overriding(
header::STRICT_TRANSPORT_SECURITY,
HeaderValue::from_static("max-age=31536000; includeSubDomains; preload"),
));

match (self.http_port(), self.https_port()) {
Expand Down Expand Up @@ -1921,4 +1925,16 @@ mod tests {
r".*<dt>output value</dt>\s*<dd>5000000000</dd>\s*<dt>content</dt>.*",
);
}

#[test]
fn strict_transport_security_header_is_set() {
assert_eq!(
TestServer::new()
.get("/status")
.headers()
.get(header::STRICT_TRANSPORT_SECURITY)
.unwrap(),
"max-age=31536000; includeSubDomains; preload",
);
}
}

0 comments on commit 7c8c93c

Please sign in to comment.