Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cdn/fastly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ mod tests {
let m = fastly_api
.mock("POST", "/service/test-sid-1/purge")
.match_header(FASTLY_KEY, "test-token")
.match_header(&SURROGATE_KEY, "crate-foo crate-bar")
.match_header(&SURROGATE_KEY, "crate-bar crate-foo")
.with_status(200)
.create_async()
.await;
Expand Down Expand Up @@ -246,7 +246,7 @@ mod tests {
let m = fastly_api
.mock("POST", "/service/test-sid-1/purge")
.match_header(FASTLY_KEY, "test-token")
.match_header(&SURROGATE_KEY, "crate-foo crate-bar")
.match_header(&SURROGATE_KEY, "crate-bar crate-foo")
.with_status(500)
.create_async()
.await;
Expand Down
6 changes: 6 additions & 0 deletions src/db/types/krate_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ use std::{io::Write, str::FromStr};
)]
pub struct KrateName(String);

impl From<&KrateName> for KrateName {
fn from(krate_name: &KrateName) -> Self {
krate_name.clone()
}
}

impl FromStr for KrateName {
type Err = anyhow::Error;

Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! [Docs.rs](https://docs.rs) (formerly cratesfyi) is an open source project to host
//! documentation of crates for the Rust Programming Language.
#![allow(clippy::cognitive_complexity)]
#![allow(
clippy::cognitive_complexity,
// TODO: `AxumNope::Redirect(EscapedURI, CachePolicy)` is too big.
clippy::result_large_err,
)]

pub use self::build_queue::{
AsyncBuildQueue, BuildQueue, queue_rebuilds, queue_rebuilds_faulty_rustdoc,
Expand Down
12 changes: 8 additions & 4 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use crate::{
storage::{AsyncStorage, Storage, StorageKind},
test::test_metrics::CollectedMetrics,
web::{
build_axum_app,
cache::{self},
headers::{IfNoneMatch, SURROGATE_CONTROL},
build_axum_app, cache,
headers::{IfNoneMatch, SURROGATE_CONTROL, SurrogateKeys},
page::TemplateData,
},
};
Expand Down Expand Up @@ -75,6 +74,11 @@ pub(crate) fn assert_cache_headers_eq(
response.headers().get(&SURROGATE_CONTROL),
"surrogate control header mismatch"
);
assert_eq!(
expected_headers.surrogate_keys.as_ref(),
response.headers().typed_get::<SurrogateKeys>().as_ref(),
"surrogate key header mismatch"
);
}

pub(crate) trait AxumResponseTestExt {
Expand Down Expand Up @@ -106,7 +110,7 @@ impl AxumResponseTestExt for axum::response::Response {
assert!(config.cache_control_stale_while_revalidate.is_some());

// This method is only about asserting if the handler did set the right _policy_.
assert_cache_headers_eq(self, &cache_policy.render(config));
assert_cache_headers_eq(self, &cache_policy.render(config).unwrap());
}

fn error_for_status(self) -> Result<Self>
Expand Down
13 changes: 7 additions & 6 deletions src/web/build_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ pub(crate) async fn build_details_handler(
let version = match_version(&mut conn, params.name(), params.req_version())
.await?
.assume_exact_name()?
.into_canonical_req_version_or_else(|version| {
.into_canonical_req_version_or_else(|confirmed_name, version| {
let params = params
.clone()
.with_confirmed_name(Some(confirmed_name))
.with_req_version(version);
AxumNope::Redirect(
params
.clone()
.with_req_version(version)
.build_details_url(id, build_params.filename.as_deref()),
CachePolicy::ForeverInCdn,
params.build_details_url(id, build_params.filename.as_deref()),
CachePolicy::ForeverInCdn(confirmed_name.into()),
)
})?
.into_version();
Expand Down
10 changes: 7 additions & 3 deletions src/web/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ pub(crate) async fn build_list_handler(
let version = match_version(&mut conn, params.name(), params.req_version())
.await?
.assume_exact_name()?
.into_canonical_req_version_or_else(|version| {
.into_canonical_req_version_or_else(|confirmed_name, version| {
let params = params
.clone()
.with_confirmed_name(Some(confirmed_name))
.with_req_version(version);
AxumNope::Redirect(
params.clone().with_req_version(version).builds_url(),
CachePolicy::ForeverInCdn,
params.builds_url(),
CachePolicy::ForeverInCdn(confirmed_name.into()),
)
})?
.into_version();
Expand Down
Loading
Loading