@@ -5,7 +5,7 @@ use crate::{Rocket, Request, Response, Orbit, Config};
5
5
use crate :: fairing:: { Fairing , Info , Kind } ;
6
6
use crate :: http:: { Header , uncased:: UncasedStr } ;
7
7
use crate :: shield:: * ;
8
- use crate :: trace:: traceable :: * ;
8
+ use crate :: trace:: * ;
9
9
10
10
/// A [`Fairing`] that injects browser security and privacy headers into all
11
11
/// outgoing responses.
@@ -59,10 +59,8 @@ use crate::trace::traceable::*;
59
59
///
60
60
/// If TLS is configured and enabled when the application is launched in a
61
61
/// non-debug profile, HSTS is automatically enabled with its default policy and
62
- /// a warning is logged.
63
- ///
64
- /// To get rid of this warning, explicitly [`Shield::enable()`] an [`Hsts`]
65
- /// policy.
62
+ /// a warning is logged. To get rid of this warning, explicitly
63
+ /// [`Shield::enable()`] an [`Hsts`] policy.
66
64
pub struct Shield {
67
65
/// Enabled policies where the key is the header name.
68
66
policies : HashMap < & ' static UncasedStr , Header < ' static > > ,
@@ -193,32 +191,19 @@ impl Fairing for Shield {
193
191
&& rocket. figment ( ) . profile ( ) != Config :: DEBUG_PROFILE
194
192
&& !self . is_enabled :: < Hsts > ( ) ;
195
193
194
+ if force_hsts {
195
+ self . force_hsts . store ( true , Ordering :: Release ) ;
196
+ }
197
+
196
198
info_span ! ( "shield" [ policies = self . policies. len( ) ] => {
197
199
self . policies. values( ) . trace_all_info( ) ;
198
200
199
201
if force_hsts {
200
- warn!( "Detected TLS-enabled liftoff without enabling HSTS." ) ;
201
- warn! ( " Shield has enabled a default HSTS policy." ) ;
202
- info! ( " To remove this warning, configure an HSTS policy.") ;
202
+ warn!( "Detected TLS-enabled liftoff without enabling HSTS.\n \
203
+ Shield has enabled a default HSTS policy.\n \
204
+ To remove this warning, configure an HSTS policy.") ;
203
205
}
204
206
} )
205
-
206
- // trace::collection_info!("shield", force_hsts => self.polices.values(), {
207
- // warn!("Detected TLS-enabled liftoff without enabling HSTS.");
208
- // warn!("Shield has enabled a default HSTS policy.");
209
- // info!("To remove this warning, configure an HSTS policy.");
210
- // });
211
-
212
- // // tracing::info_span!("shield", force_hsts).in_scope(|| {
213
- // // self.polices.values().trace();
214
- // // for header in self.policies.values() {
215
- // // info!(name: "header", name = header.name().as_str(), value = header.value());
216
- // // }
217
- //
218
- // warn!("Detected TLS-enabled liftoff without enabling HSTS.");
219
- // warn!("Shield has enabled a default HSTS policy.");
220
- // info!("To remove this warning, configure an HSTS policy.");
221
- // });
222
207
}
223
208
224
209
async fn on_response < ' r > ( & self , _: & ' r Request < ' _ > , response : & mut Response < ' r > ) {
0 commit comments