File tree 3 files changed +16
-8
lines changed
3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -61,12 +61,17 @@ pub(crate) fn assert_cache_control(
61
61
config : & Config ,
62
62
) {
63
63
assert ! ( config. cache_control_stale_while_revalidate. is_some( ) ) ;
64
- assert_eq ! (
65
- res. headers( )
66
- . get( "Cache-Control" )
67
- . expect( "missing cache-control header" ) ,
68
- & CacheControl ( cache_policy. render( config) ) . to_string( )
69
- ) ;
64
+ let cache_control = res. headers ( ) . get ( "Cache-Control" ) ;
65
+
66
+ let expected_directives = cache_policy. render ( config) ;
67
+ if expected_directives. is_empty ( ) {
68
+ assert ! ( cache_control. is_none( ) ) ;
69
+ } else {
70
+ assert_eq ! (
71
+ cache_control. expect( "missing cache-control header" ) ,
72
+ & CacheControl ( expected_directives) . to_string( )
73
+ ) ;
74
+ }
70
75
}
71
76
72
77
/// Make sure that a URL returns a status code between 200-299
Original file line number Diff line number Diff line change @@ -104,7 +104,10 @@ impl AfterMiddleware for CacheMiddleware {
104
104
) ;
105
105
}
106
106
107
- res. headers . set ( CacheControl ( cache. render ( config) ) ) ;
107
+ let directives = cache. render ( config) ;
108
+ if !directives. is_empty ( ) {
109
+ res. headers . set ( CacheControl ( directives) )
110
+ }
108
111
Ok ( res)
109
112
}
110
113
}
Original file line number Diff line number Diff line change @@ -1769,7 +1769,7 @@ mod test {
1769
1769
let url = format ! ( "http://{}/dummy" , web. server_addr( ) ) ;
1770
1770
let resp = client. get ( url) . send ( ) ?;
1771
1771
assert_eq ! ( resp. status( ) , StatusCode :: FOUND ) ;
1772
- assert ! ( resp. headers( ) . get( "Cache-Control" ) . unwrap ( ) . is_empty ( ) ) ;
1772
+ assert ! ( resp. headers( ) . get( "Cache-Control" ) . is_none ( ) ) ;
1773
1773
assert ! ( resp
1774
1774
. headers( )
1775
1775
. get( "Location" )
You can’t perform that action at this time.
0 commit comments