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