acme: inline nonce handling
This commit is contained in:
parent
40a561ffb5
commit
5be34c546c
29
src/lib.rs
29
src/lib.rs
|
@ -259,15 +259,22 @@ impl Client {
|
||||||
async fn post(
|
async fn post(
|
||||||
&self,
|
&self,
|
||||||
payload: Option<&impl Serialize>,
|
payload: Option<&impl Serialize>,
|
||||||
nonce: Option<String>,
|
mut nonce: Option<String>,
|
||||||
signer: &impl Signer,
|
signer: &impl Signer,
|
||||||
url: &str,
|
url: &str,
|
||||||
) -> Result<Response<Body>, Error> {
|
) -> Result<Response<Body>, Error> {
|
||||||
let nonce = match nonce {
|
if nonce.is_none() {
|
||||||
Some(nonce) => nonce,
|
let request = Request::builder()
|
||||||
None => self.nonce().await?,
|
.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()
|
let request = Request::builder()
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
.uri(url)
|
.uri(url)
|
||||||
|
@ -277,20 +284,6 @@ impl Client {
|
||||||
|
|
||||||
Ok(self.client.request(request).await?)
|
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 {
|
struct Key {
|
||||||
|
|
Loading…
Reference in New Issue