Skip to content

Commit

Permalink
Release v0.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Sep 10, 2024
1 parent af53b55 commit 97e9938
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "GPL-3.0"
name = "reqwew"
readme = "README.md"
repository = "https://github.com/hack-ink/reqwew"
version = "0.2.4"
version = "0.2.5"

[profile.ci-dev]
incremental = false
Expand Down
50 changes: 50 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,44 @@ where
Err(Error::ExceededMaxRetries { retries })?
}
}

/// Perform a PUT request.
fn put<U, B>(&self, uri: U, body: B) -> impl Future<Output = Result<Bytes>> + Send
where
U: Send + IntoUrl,
B: Send + Into<Body>;

/// Perform a PUT request with retries.
fn put_with_retries<U, B>(
&self,
uri: U,
body: B,
retries: u32,
retry_delay_ms: u64,
) -> impl Future<Output = Result<Bytes>> + Send
where
U: Send + IntoUrl,
B: Send + Clone + Into<Body>,
{
async move {
let u = uri.as_str();

for i in 1..=retries {
match self.put(u, body.clone()).await {
Ok(r) => return Ok(r),
Err(e) => {
tracing::error!(
"attempt {i}/{retries} failed for {u}: {e:?}, \
retrying in {retry_delay_ms}ms"
);
time::sleep(Duration::from_millis(retry_delay_ms)).await;
},
}
}

Err(Error::ExceededMaxRetries { retries })?
}
}
}

/// [`reqwest::Response`] wrapper.
Expand Down Expand Up @@ -166,6 +204,18 @@ impl Http for Client {

async move { Ok(self.0.post(uri).body(body).send().await?.bytes().await?) }
}

fn put<U, B>(&self, uri: U, body: B) -> impl Future<Output = Result<Bytes>> + Send
where
U: Send + IntoUrl,
B: Send + Into<Body>,
{
let u = uri.as_str();

tracing::debug!("PUT {u}");

async move { Ok(self.0.put(uri).body(body).send().await?.bytes().await?) }
}
}

/// Create a new static [`Client`] instance.
Expand Down

0 comments on commit 97e9938

Please sign in to comment.