@@ -42,35 +42,6 @@ static DOC_RUST_LANG_ORG_REDIRECTS: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
42
42
] )
43
43
} ) ;
44
44
45
- fn generate_cache_directives_for (
46
- max_age : Option < u32 > ,
47
- s_max_age : Option < u32 > ,
48
- stale_while_revalidate : Option < u32 > ,
49
- ) -> Option < CacheControl > {
50
- let mut directives = vec ! [ ] ;
51
-
52
- if let Some ( seconds) = stale_while_revalidate {
53
- directives. push ( CacheDirective :: Extension (
54
- "stale-while-revalidate" . to_string ( ) ,
55
- Some ( format ! ( "{}" , seconds) ) ,
56
- ) ) ;
57
- }
58
-
59
- if let Some ( seconds) = max_age {
60
- directives. push ( CacheDirective :: MaxAge ( seconds) ) ;
61
- }
62
-
63
- if let Some ( seconds) = s_max_age {
64
- directives. push ( CacheDirective :: SMaxAge ( seconds) ) ;
65
- }
66
-
67
- if !directives. is_empty ( ) {
68
- Some ( CacheControl ( directives) )
69
- } else {
70
- None
71
- }
72
- }
73
-
74
45
/// Handler called for `/:crate` and `/:crate/:version` URLs. Automatically redirects to the docs
75
46
/// or crate details page based on whether the given crate version was successfully built.
76
47
pub fn rustdoc_redirector_handler ( req : & mut Request ) -> IronResult < Response > {
@@ -290,21 +261,26 @@ impl RustdocPage {
290
261
let mut response = Response :: with ( ( Status :: Ok , html) ) ;
291
262
response. headers . set ( ContentType :: html ( ) ) ;
292
263
293
- let cache_control = if is_latest_url {
294
- generate_cache_directives_for (
295
- Some ( config. cache_control_max_age_latest . unwrap_or ( 0 ) ) ,
296
- config. cache_control_s_max_age_latest ,
297
- config. cache_control_stale_while_revalidate_latest ,
298
- )
264
+ if is_latest_url {
265
+ response
266
+ . headers
267
+ . set ( CacheControl ( vec ! [ CacheDirective :: MaxAge ( 0 ) ] ) ) ;
299
268
} else {
300
- generate_cache_directives_for (
301
- config. cache_control_max_age ,
302
- config. cache_control_s_max_age ,
303
- config. cache_control_stale_while_revalidate ,
304
- )
305
- } ;
306
- if let Some ( cache_control) = cache_control {
307
- response. headers . set ( cache_control) ;
269
+ let mut directives = vec ! [ ] ;
270
+ if let Some ( seconds) = config. cache_control_stale_while_revalidate {
271
+ directives. push ( CacheDirective :: Extension (
272
+ "stale-while-revalidate" . to_string ( ) ,
273
+ Some ( format ! ( "{}" , seconds) ) ,
274
+ ) ) ;
275
+ }
276
+
277
+ if let Some ( seconds) = config. cache_control_max_age {
278
+ directives. push ( CacheDirective :: MaxAge ( seconds) ) ;
279
+ }
280
+
281
+ if !directives. is_empty ( ) {
282
+ response. headers . set ( CacheControl ( directives) ) ;
283
+ }
308
284
}
309
285
Ok ( response)
310
286
}
@@ -912,39 +888,6 @@ mod test {
912
888
} )
913
889
}
914
890
915
- #[ test]
916
- fn cache_headers_only_latest ( ) {
917
- wrapper ( |env| {
918
- env. override_config ( |config| {
919
- config. cache_control_max_age_latest = Some ( 600 ) ;
920
- config. cache_control_stale_while_revalidate_latest = Some ( 2592000 ) ;
921
- } ) ;
922
-
923
- env. fake_release ( )
924
- . name ( "dummy" )
925
- . version ( "0.1.0" )
926
- . archive_storage ( true )
927
- . rustdoc_file ( "dummy/index.html" )
928
- . create ( ) ?;
929
-
930
- let web = env. frontend ( ) ;
931
-
932
- {
933
- let resp = web. get ( "/dummy/latest/dummy/" ) . send ( ) ?;
934
- assert_eq ! (
935
- resp. headers( ) . get( "Cache-Control" ) . unwrap( ) ,
936
- & "stale-while-revalidate=2592000, max-age=600"
937
- ) ;
938
- }
939
-
940
- {
941
- let resp = web. get ( "/dummy/0.1.0/dummy/" ) . send ( ) ?;
942
- assert ! ( resp. headers( ) . get( "Cache-Control" ) . is_none( ) ) ;
943
- }
944
- Ok ( ( ) )
945
- } )
946
- }
947
-
948
891
#[ test]
949
892
fn cache_headers_on_version ( ) {
950
893
wrapper ( |env| {
@@ -978,46 +921,6 @@ mod test {
978
921
} )
979
922
}
980
923
981
- #[ test]
982
- fn cache_headers_latest_and_version ( ) {
983
- wrapper ( |env| {
984
- env. override_config ( |config| {
985
- config. cache_control_max_age = Some ( 666 ) ;
986
- config. cache_control_s_max_age = Some ( 777 ) ;
987
- config. cache_control_max_age_latest = Some ( 999 ) ;
988
- config. cache_control_s_max_age_latest = Some ( 888 ) ;
989
- config. cache_control_stale_while_revalidate = Some ( 2222222 ) ;
990
- config. cache_control_stale_while_revalidate_latest = Some ( 3333333 ) ;
991
- } ) ;
992
-
993
- env. fake_release ( )
994
- . name ( "dummy" )
995
- . version ( "0.1.0" )
996
- . archive_storage ( true )
997
- . rustdoc_file ( "dummy/index.html" )
998
- . create ( ) ?;
999
-
1000
- let web = env. frontend ( ) ;
1001
-
1002
- {
1003
- let resp = web. get ( "/dummy/latest/dummy/" ) . send ( ) ?;
1004
- assert_eq ! (
1005
- resp. headers( ) . get( "Cache-Control" ) . unwrap( ) ,
1006
- & "stale-while-revalidate=3333333, max-age=999, s-maxage=888"
1007
- ) ;
1008
- }
1009
-
1010
- {
1011
- let resp = web. get ( "/dummy/0.1.0/dummy/" ) . send ( ) ?;
1012
- assert_eq ! (
1013
- resp. headers( ) . get( "Cache-Control" ) . unwrap( ) ,
1014
- & "stale-while-revalidate=2222222, max-age=666, s-maxage=777"
1015
- ) ;
1016
- }
1017
- Ok ( ( ) )
1018
- } )
1019
- }
1020
-
1021
924
#[ test_case( true ) ]
1022
925
#[ test_case( false ) ]
1023
926
fn go_to_latest_version ( archive_storage : bool ) {
0 commit comments