Skip to content

Commit 90fb283

Browse files
committed
fastly: Simplify header setting code
1 parent e7c5e5e commit 90fb283

File tree

1 file changed

+10
-9
lines changed
  • crates/crates_io_fastly/src

1 file changed

+10
-9
lines changed

crates/crates_io_fastly/src/lib.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use anyhow::{Context, anyhow};
44
use reqwest::Client;
5-
use reqwest::header::{HeaderMap, HeaderValue};
5+
use reqwest::header::{HeaderMap, HeaderValue, InvalidHeaderValue};
66
use secrecy::{ExposeSecret, SecretString};
77
use tracing::{debug, instrument, trace};
88

@@ -60,18 +60,11 @@ impl Fastly {
6060

6161
trace!(?url);
6262

63-
let api_token = self.api_token.expose_secret();
64-
let mut api_token = HeaderValue::try_from(api_token)?;
65-
api_token.set_sensitive(true);
66-
67-
let mut headers = HeaderMap::new();
68-
headers.append("Fastly-Key", api_token);
69-
7063
debug!("sending invalidation request to Fastly");
7164
let response = self
7265
.client
7366
.post(&url)
74-
.headers(headers)
67+
.header("Fastly-Key", self.token_header_value()?)
7568
.send()
7669
.await
7770
.context("failed to send invalidation request to Fastly")?;
@@ -97,4 +90,12 @@ impl Fastly {
9790
}
9891
}
9992
}
93+
94+
fn token_header_value(&self) -> Result<HeaderValue, InvalidHeaderValue> {
95+
let api_token = self.api_token.expose_secret();
96+
97+
let mut header_value = HeaderValue::try_from(api_token)?;
98+
header_value.set_sensitive(true);
99+
Ok(header_value)
100+
}
100101
}

0 commit comments

Comments
 (0)