Skip to content

Commit

Permalink
fetch, send: run signature in spawn_blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jun 7, 2024
1 parent cd36a9e commit fa47217
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ where
.header("accept", "application/activity+json")
.header("digest", digest_header)
.body(vec![])?;
SigningConfig::new(RsaSha256, private_key, key_id)
.sign(&mut req)?;
let private_key = private_key.clone();
let key_id = key_id.to_string();
let req = spawn_blocking(move || {
SigningConfig::new(RsaSha256, &private_key, &key_id).sign(&mut req)?;
Ok(req)
})
.await
.map_err(|e| Error::Response(format!("{e}")))?
.map_err(|e: sigh::Error| Error::Response(format!("{e}")))?;
let req: reqwest::Request = req.try_into()?;
let res = client.execute(req)
.await?;
let res = client.execute(req).await?;
if res.status() >= StatusCode::OK && res.status() < StatusCode::MULTIPLE_CHOICES {
Ok(res.json().await?)
} else {
Expand Down
14 changes: 10 additions & 4 deletions src/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ pub async fn send_raw(
.header("digest", digest_header)
.body(body.as_ref().clone())?;
let t1 = Instant::now();
SigningConfig::new(RsaSha256, private_key, key_id)
.sign(&mut req)?;
let private_key = private_key.clone();
let key_id = key_id.to_string();
let req = spawn_blocking(move || {
SigningConfig::new(RsaSha256, &private_key, &key_id).sign(&mut req)?;
Ok(req)
})
.await
.map_err(|e| Error::Response(format!("{e}")))?
.map_err(|e: sigh::Error| Error::Response(format!("{e}")))?;
let t2 = Instant::now();
let req: reqwest::Request = req.try_into()?;
let res = client.execute(req)
.await?;
let res = client.execute(req).await?;
let t3 = Instant::now();
histogram!("relay_http_request_duration")
.record(t2 - t1);
Expand Down

0 comments on commit fa47217

Please sign in to comment.