1+ //! Crate that provides helpers, and/or middlewares for tide
2+ //! related to http headers.
3+ #![ feature( async_await) ]
4+ #![ warn(
5+ nonstandard_style,
6+ rust_2018_idioms,
7+ future_incompatible,
8+ missing_debug_implementations
9+ ) ]
10+
111use futures:: future:: BoxFuture ;
212use futures:: prelude:: * ;
13+ use log:: trace;
314
415use http:: {
516 header:: { HeaderValue , IntoHeaderName } ,
617 HeaderMap , HttpTryFrom ,
718} ;
819
9- use crate :: {
20+ use tide_core :: {
1021 middleware:: { Middleware , Next } ,
1122 Context , Response ,
1223} ;
@@ -20,10 +31,9 @@ pub struct DefaultHeaders {
2031impl DefaultHeaders {
2132 /// Construct a new instance with an empty list of headers.
2233 pub fn new ( ) -> DefaultHeaders {
23- DefaultHeaders :: default ( )
34+ Self :: default ( )
2435 }
2536
26- #[ inline]
2737 /// Add a header to the default header list.
2838 pub fn header < K , V > ( mut self , key : K , value : V ) -> Self
2939 where
@@ -35,7 +45,6 @@ impl DefaultHeaders {
3545 . expect ( "Cannot create default header" ) ;
3646
3747 self . headers . append ( key, value) ;
38-
3948 self
4049 }
4150}
@@ -44,9 +53,9 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for DefaultHeaders {
4453 fn handle < ' a > ( & ' a self , cx : Context < Data > , next : Next < ' a , Data > ) -> BoxFuture < ' a , Response > {
4554 FutureExt :: boxed ( async move {
4655 let mut res = next. run ( cx) . await ;
47-
4856 let headers = res. headers_mut ( ) ;
4957 for ( key, value) in self . headers . iter ( ) {
58+ trace ! ( "add default: {} {:?}" , & key, & value) ;
5059 headers. entry ( key) . unwrap ( ) . or_insert_with ( || value. clone ( ) ) ;
5160 }
5261 res
0 commit comments