Skip to content

Commit 3e3c257

Browse files
committed
rename CachePolicy::ForeverOnlyInCdn into ForeverInCdn
1 parent 5853ffa commit 3e3c257

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

src/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl TestEnvironment {
263263
config.local_archive_cache_path =
264264
std::env::temp_dir().join(format!("docsrs-test-index-{}", rand::random::<u64>()));
265265

266-
// set stale content serving so Cache::ForeverOnlyInCdn and Cache::ForeverInCdnAndStaleInBrowser
266+
// set stale content serving so Cache::ForeverInCdn and Cache::ForeverInCdnAndStaleInBrowser
267267
// are actually different.
268268
config.cache_control_stale_while_revalidate = Some(86400);
269269

src/web/cache.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum CachePolicy {
2727
/// Since we control the CDN we can actively purge content that is cached like
2828
/// this, for example after building a crate.
2929
/// Example usage: `/latest/` rustdoc pages and their redirects.
30-
ForeverOnlyInCdn,
30+
ForeverInCdn,
3131
/// cache forver in the CDN, but allow stale content in the browser.
3232
/// Example: rustdoc pages with the version in their URL.
3333
/// A browser will show the stale content while getting the up-to-date
@@ -56,7 +56,7 @@ impl CachePolicy {
5656
CacheDirective::MaxAge(STATIC_FILE_CACHE_DURATION as u32),
5757
]
5858
}
59-
CachePolicy::ForeverOnlyInCdn => {
59+
CachePolicy::ForeverInCdn => {
6060
// A missing `max-age` or `s-maxage` in the Cache-Control header will lead to
6161
// CloudFront using the default TTL, while the browser not seeing any caching header.
6262
// This means we can have the CDN caching the documentation while just
@@ -65,7 +65,7 @@ impl CachePolicy {
6565
vec![CacheDirective::Public]
6666
}
6767
CachePolicy::ForeverInCdnAndStaleInBrowser => {
68-
let mut directives = CachePolicy::ForeverOnlyInCdn.render(config);
68+
let mut directives = CachePolicy::ForeverInCdn.render(config);
6969
if let Some(seconds) = config.cache_control_stale_while_revalidate {
7070
directives.push(CacheDirective::Extension(
7171
"stale-while-revalidate".to_string(),
@@ -86,8 +86,8 @@ impl iron::typemap::Key for CachePolicy {
8686
/// The default is an explicit "never cache" header, which
8787
/// can be adapted via:
8888
/// ```ignore
89-
/// resp.extensions.insert::<CachePolicy>(CachePolicy::ForeverOnlyInCdn);
90-
/// # change Cache::ForeverOnlyInCdn into the cache polity you want to have
89+
/// resp.extensions.insert::<CachePolicy>(CachePolicy::ForeverInCdn);
90+
/// # change Cache::ForeverInCdn into the cache polity you want to have
9191
/// ```
9292
/// in a handler function.
9393
pub(super) struct CacheMiddleware;
@@ -125,7 +125,7 @@ mod tests {
125125
"no-cache, no-store, must-revalidate, max-age=0"
126126
)]
127127
#[test_case(CachePolicy::ForeverInCdnAndBrowser, "public, max-age=31104000")]
128-
#[test_case(CachePolicy::ForeverOnlyInCdn, "public")]
128+
#[test_case(CachePolicy::ForeverInCdn, "public")]
129129
#[test_case(
130130
CachePolicy::ForeverInCdnAndStaleInBrowser,
131131
"public, stale-while-revalidate=86400"

src/web/crate_details.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ pub fn crate_details_handler(req: &mut Request) -> IronResult<Response> {
308308
req,
309309
Url::parse(&format!("{}/crate/{}/latest", redirect_base(req), name,)),
310310
);
311-
return Ok(super::cached_redirect(url, CachePolicy::ForeverOnlyInCdn));
311+
return Ok(super::cached_redirect(url, CachePolicy::ForeverInCdn));
312312
}
313313

314314
let mut conn = extension!(req, Pool).get()?;
@@ -329,7 +329,7 @@ pub fn crate_details_handler(req: &mut Request) -> IronResult<Response> {
329329
)),
330330
);
331331

332-
return Ok(super::cached_redirect(url, CachePolicy::ForeverOnlyInCdn));
332+
return Ok(super::cached_redirect(url, CachePolicy::ForeverInCdn));
333333
}
334334
};
335335

@@ -350,7 +350,7 @@ pub fn crate_details_handler(req: &mut Request) -> IronResult<Response> {
350350

351351
let mut res = CrateDetailsPage { details }.into_response(req)?;
352352
res.extensions.insert::<CachePolicy>(if is_latest_url {
353-
CachePolicy::ForeverOnlyInCdn
353+
CachePolicy::ForeverInCdn
354354
} else {
355355
CachePolicy::ForeverInCdnAndStaleInBrowser
356356
});
@@ -1027,7 +1027,7 @@ mod tests {
10271027

10281028
let resp = env.frontend().get("/crate/dummy/latest").send()?;
10291029
assert!(resp.status().is_success());
1030-
assert_cache_control(&resp, CachePolicy::ForeverOnlyInCdn, &env.config());
1030+
assert_cache_control(&resp, CachePolicy::ForeverInCdn, &env.config());
10311031
assert!(resp.url().as_str().ends_with("/crate/dummy/latest"));
10321032
let body = String::from_utf8(resp.bytes().unwrap().to_vec()).unwrap();
10331033
assert!(body.contains("<a href=\"/crate/dummy/latest/features\""));
@@ -1045,7 +1045,7 @@ mod tests {
10451045
assert_redirect_cached(
10461046
"/crate/dummy",
10471047
"/crate/dummy/latest",
1048-
CachePolicy::ForeverOnlyInCdn,
1048+
CachePolicy::ForeverInCdn,
10491049
web,
10501050
&env.config(),
10511051
)?;

src/web/rustdoc.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
6767

6868
let mut resp = Response::with((status::Found, Redirect(url)));
6969
resp.extensions
70-
.insert::<CachePolicy>(CachePolicy::ForeverOnlyInCdn);
70+
.insert::<CachePolicy>(CachePolicy::ForeverInCdn);
7171
Ok(resp)
7272
}
7373

@@ -190,7 +190,7 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
190190
};
191191

192192
let cache = if version == "latest" {
193-
CachePolicy::ForeverOnlyInCdn
193+
CachePolicy::ForeverInCdn
194194
} else {
195195
CachePolicy::ForeverInCdnAndStaleInBrowser
196196
};
@@ -263,7 +263,7 @@ impl RustdocPage {
263263
let mut response = Response::with((Status::Ok, html));
264264
response.headers.set(ContentType::html());
265265
response.extensions.insert::<CachePolicy>(if is_latest_url {
266-
CachePolicy::ForeverOnlyInCdn
266+
CachePolicy::ForeverInCdn
267267
} else {
268268
CachePolicy::ForeverInCdnAndStaleInBrowser
269269
});
@@ -356,7 +356,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
356356
// to prevent cloudfront caching the wrong artifacts on URLs with loose semver
357357
// versions, redirect the browser to the returned version instead of loading it
358358
// immediately
359-
return redirect(&name, &v, &req_path, CachePolicy::ForeverOnlyInCdn);
359+
return redirect(&name, &v, &req_path, CachePolicy::ForeverInCdn);
360360
}
361361
};
362362

@@ -387,7 +387,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
387387
&name,
388388
&version_or_latest,
389389
&req_path[1..],
390-
CachePolicy::ForeverOnlyInCdn,
390+
CachePolicy::ForeverInCdn,
391391
);
392392
}
393393

@@ -427,7 +427,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
427427
&name,
428428
&version_or_latest,
429429
&req_path,
430-
CachePolicy::ForeverOnlyInCdn,
430+
CachePolicy::ForeverInCdn,
431431
)
432432
} else if req_path.first().map_or(false, |p| p.contains('-')) {
433433
// This is a target, not a module; it may not have been built.
@@ -436,7 +436,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
436436
&format!("/crate/{}", name),
437437
&format!("{}/target-redirect", version),
438438
&req_path,
439-
CachePolicy::ForeverOnlyInCdn,
439+
CachePolicy::ForeverInCdn,
440440
)
441441
} else {
442442
Err(Nope::ResourceNotFound.into())
@@ -456,7 +456,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
456456
// which means we cache slightly different for `/latest/` and
457457
// URLs with versions.
458458
response.extensions.insert::<CachePolicy>(if is_latest_url {
459-
CachePolicy::ForeverOnlyInCdn
459+
CachePolicy::ForeverInCdn
460460
} else {
461461
CachePolicy::ForeverInCdnAndStaleInBrowser
462462
});
@@ -701,7 +701,7 @@ pub fn target_redirect_handler(req: &mut Request) -> IronResult<Response> {
701701
let url = ctry!(req, Url::parse(&url));
702702
let mut resp = Response::with((status::Found, Redirect(url)));
703703
resp.extensions.insert::<CachePolicy>(if is_latest_url {
704-
CachePolicy::ForeverOnlyInCdn
704+
CachePolicy::ForeverInCdn
705705
} else {
706706
CachePolicy::ForeverInCdnAndStaleInBrowser
707707
});
@@ -788,7 +788,7 @@ mod test {
788788
.next()
789789
{
790790
let link = elem.attributes.borrow().get("href").unwrap().to_string();
791-
assert_success_cached(&link, web, CachePolicy::ForeverOnlyInCdn, config)?;
791+
assert_success_cached(&link, web, CachePolicy::ForeverInCdn, config)?;
792792
Ok(Some(link))
793793
} else {
794794
Ok(None)
@@ -898,7 +898,7 @@ mod test {
898898
assert_redirect_cached(
899899
"/dummy/0.1.0/x86_64-unknown-linux-gnu/dummy/",
900900
base,
901-
CachePolicy::ForeverOnlyInCdn,
901+
CachePolicy::ForeverInCdn,
902902
web,
903903
&env.config(),
904904
)?;
@@ -954,7 +954,7 @@ mod test {
954954
.create()?;
955955

956956
let resp = env.frontend().get("/dummy/latest/dummy/").send()?;
957-
assert_cache_control(&resp, CachePolicy::ForeverOnlyInCdn, &env.config());
957+
assert_cache_control(&resp, CachePolicy::ForeverInCdn, &env.config());
958958
assert!(resp.url().as_str().ends_with("/dummy/latest/dummy/"));
959959
let body = String::from_utf8(resp.bytes().unwrap().to_vec()).unwrap();
960960
assert!(body.contains("<a href=\"/crate/dummy/latest/source/\""));
@@ -982,7 +982,7 @@ mod test {
982982

983983
{
984984
let resp = web.get("/dummy/latest/dummy/").send()?;
985-
assert_cache_control(&resp, CachePolicy::ForeverOnlyInCdn, &env.config());
985+
assert_cache_control(&resp, CachePolicy::ForeverInCdn, &env.config());
986986
}
987987

988988
{

0 commit comments

Comments
 (0)