Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All significant changes to the `percase-client` crate will be documented in this

## Unreleased

### New features

* Added `Client::put_owned` to avoid an extra copy when the caller has ownership of the data.

## v0.3.0 (2025-10-14)

### Breaking changes
Expand Down
30 changes: 30 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::time::Duration;
use std::time::Instant;

use fastrace_reqwest::traceparent_headers;
use reqwest::Body;
use reqwest::StatusCode;
use reqwest::Url;
use reqwest::redirect::Policy;
Expand Down Expand Up @@ -155,6 +156,35 @@ impl Client {
}
}

/// Set the value associated with the given key.
///
/// This method exists to avoid an extra copy when the caller has ownership of the data:
///
/// * `&'static str`
/// * `Vec<u8>`
/// * `bytes::Bytes`
/// * `reqwest::Body`
pub async fn put_owned<T: Into<Body>>(&self, key: &str, value: T) -> Result<(), Error> {
self.update_route_table_if_needed().await?;

let url = self.route(key).join(key).map_err(make_opaque_error)?;

let resp = self
.client
.put(url)
.headers(traceparent_headers())
.body(value)
.send()
.await
.map_err(make_opaque_error)?;

match resp.status() {
StatusCode::OK | StatusCode::CREATED => Ok(()),
StatusCode::TOO_MANY_REQUESTS => Err(Error::TooManyRequests),
status => Err(make_opaque_error(status)),
}
}

/// Delete the value associated with the given key.
pub async fn delete(&self, key: &str) -> Result<(), Error> {
self.update_route_table_if_needed().await?;
Expand Down
Loading