acme: inline nonce handling

This commit is contained in:
Dirkjan Ochtman 2022-05-10 15:08:45 +02:00 committed by Dirkjan Ochtman
parent 40a561ffb5
commit 5be34c546c
1 changed files with 11 additions and 18 deletions

View File

@ -259,15 +259,22 @@ impl Client {
async fn post(
&self,
payload: Option<&impl Serialize>,
nonce: Option<String>,
mut nonce: Option<String>,
signer: &impl Signer,
url: &str,
) -> Result<Response<Body>, Error> {
let nonce = match nonce {
Some(nonce) => nonce,
None => self.nonce().await?,
if nonce.is_none() {
let request = Request::builder()
.method(Method::HEAD)
.uri(&self.urls.new_nonce)
.body(Body::empty())
.unwrap();
let rsp = self.client.request(request).await?;
nonce = nonce_from_response(&rsp);
};
let nonce = nonce.ok_or("no nonce found")?;
let request = Request::builder()
.method(Method::POST)
.uri(url)
@ -277,20 +284,6 @@ impl Client {
Ok(self.client.request(request).await?)
}
async fn nonce(&self) -> Result<String, Error> {
let request = Request::builder()
.method(Method::HEAD)
.uri(&self.urls.new_nonce)
.body(Body::empty())
.unwrap();
let rsp = self.client.request(request).await?;
match nonce_from_response(&rsp) {
Some(nonce) => Ok(nonce),
None => Err("no nonce found".into()),
}
}
}
struct Key {