From 376a99330d3f9f182f2bc9a3d1a3dc308b144983 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 13 Nov 2025 12:05:54 +0100 Subject: [PATCH] fastly: Refactor `purge()` to accept domain and path We currently only allow invalidation of files on the `static.crates.io` domain, but not for `index.crates.io`. This adjusts the `Fastly` API to allow this in the future. --- src/fastly.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/fastly.rs b/src/fastly.rs index ae865c83771..03b45839357 100644 --- a/src/fastly.rs +++ b/src/fastly.rs @@ -46,17 +46,19 @@ impl Fastly { &self.static_domain_name, &format!("fastly-{}", self.static_domain_name), ]; - let path = path.trim_start_matches('/'); - for domain in domains.iter() { - let url = format!("https://api.fastly.com/purge/{domain}/{path}"); - self.purge_url(&url).await?; + for domain in domains { + self.purge(domain, path).await?; } Ok(()) } - async fn purge_url(&self, url: &str) -> anyhow::Result<()> { + #[instrument(skip(self))] + pub async fn purge(&self, domain: &str, path: &str) -> anyhow::Result<()> { + let path = path.trim_start_matches('/'); + let url = format!("https://api.fastly.com/purge/{domain}/{path}"); + trace!(?url); let api_token = self.api_token.expose_secret(); @@ -69,7 +71,7 @@ impl Fastly { debug!("sending invalidation request to Fastly"); let response = self .client - .post(url) + .post(&url) .headers(headers) .send() .await