Skip to content

Commit 9b905fd

Browse files
authored
fastly: Refactor purge() to accept domain and path (#12321)
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.
1 parent a88f495 commit 9b905fd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/fastly.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ impl Fastly {
4646
&self.static_domain_name,
4747
&format!("fastly-{}", self.static_domain_name),
4848
];
49-
let path = path.trim_start_matches('/');
5049

51-
for domain in domains.iter() {
52-
let url = format!("https://api.fastly.com/purge/{domain}/{path}");
53-
self.purge_url(&url).await?;
50+
for domain in domains {
51+
self.purge(domain, path).await?;
5452
}
5553

5654
Ok(())
5755
}
5856

59-
async fn purge_url(&self, url: &str) -> anyhow::Result<()> {
57+
#[instrument(skip(self))]
58+
pub async fn purge(&self, domain: &str, path: &str) -> anyhow::Result<()> {
59+
let path = path.trim_start_matches('/');
60+
let url = format!("https://api.fastly.com/purge/{domain}/{path}");
61+
6062
trace!(?url);
6163

6264
let api_token = self.api_token.expose_secret();
@@ -69,7 +71,7 @@ impl Fastly {
6971
debug!("sending invalidation request to Fastly");
7072
let response = self
7173
.client
72-
.post(url)
74+
.post(&url)
7375
.headers(headers)
7476
.send()
7577
.await

0 commit comments

Comments
 (0)