@@ -2,7 +2,7 @@ use fastly::{
22 Error , Request , Response , SecretStore ,
33 http:: {
44 HeaderName , Method , StatusCode ,
5- header:: { CACHE_CONTROL , EXPIRES } ,
5+ header:: { CACHE_CONTROL , EXPIRES , STRICT_TRANSPORT_SECURITY } ,
66 } ,
77} ;
88
@@ -13,6 +13,11 @@ const DOCS_RS_SECRET_STORE: &str = "docs_rs_secrets";
1313// Should match the secret item key in terraform
1414const ORIGIN_AUTH_KEY : & str = "origin-auth" ;
1515
16+ const SURROGATE_CONTROL : HeaderName = HeaderName :: from_static ( "surrogate-control" ) ;
17+ const X_ROBOTS_TAG : HeaderName = HeaderName :: from_static ( "x-robots-tag" ) ;
18+ const X_ORIGIN_AUTH : HeaderName = HeaderName :: from_static ( "x-origin-auth" ) ;
19+ const X_COMPRESS_HINT : HeaderName = HeaderName :: from_static ( "x-compress-hint" ) ;
20+
1621#[ fastly:: main]
1722fn main ( mut req : Request ) -> Result < Response , Error > {
1823 let secrets = SecretStore :: open ( DOCS_RS_SECRET_STORE ) . expect ( "failed to open secret store" ) ;
@@ -40,8 +45,7 @@ fn main(mut req: Request) -> Result<Response, Error> {
4045 //
4146 // Related docs:
4247 // https://www.fastly.com/documentation/guides/concepts/edge-state/cache/#controlling-cache-behavior-based-on-backend-response
43- let surrogate_control = HeaderName :: from_static ( "surrogate-control" ) ;
44- let has_any_cache_headers = [ CACHE_CONTROL , surrogate_control, EXPIRES ]
48+ let has_any_cache_headers = [ CACHE_CONTROL , SURROGATE_CONTROL , EXPIRES ]
4549 . iter ( )
4650 . any ( |header| response_candidate. contains_header ( header) ) ;
4751
@@ -66,14 +70,25 @@ fn main(mut req: Request) -> Result<Response, Error> {
6670 }
6771 }
6872
69- req. set_header ( "X-Origin-Auth" , origin_auth. as_ref ( ) ) ;
73+ req. set_header ( X_ORIGIN_AUTH , origin_auth. as_ref ( ) ) ;
7074
7175 // Send request to backend
7276 let mut resp = req. send ( DOCS_RS_BACKEND ) ?;
7377
78+ // set HSTS header
79+ resp. set_header (
80+ STRICT_TRANSPORT_SECURITY ,
81+ // FIXME: this should be made configurable for test environments
82+ "max-age=31557600" ,
83+ ) ;
84+
85+ // enable dynamic compression at the edge
86+ // https://www.fastly.com/documentation/guides/concepts/compression/#dynamic-compression
87+ resp. set_header ( X_COMPRESS_HINT , "on" ) ;
88+
7489 // Prevent indexing by search engines
7590 // TODO: remove this when we are ready to go live with fastly
76- resp. set_header ( "X-Robots-Tag" , "noindex, nofollow" ) ;
91+ resp. set_header ( X_ROBOTS_TAG , "noindex, nofollow" ) ;
7792
7893 Ok ( resp)
7994}
0 commit comments