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
2 changes: 1 addition & 1 deletion examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn main() {
url: url.clone(),
method: "POST".into(),
headers: HashMap::new(),
body: Some(code.as_bytes().to_vec()),
body: Some(code.as_bytes().to_vec().into()),
};
match http.execute(req).await {
Ok(resp) if (200..300).contains(&resp.status_code) => {
Expand Down
6 changes: 4 additions & 2 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ impl Client {
file_enc_sha256: enc.file_enc_sha256,
streaming_sidecar: enc.streaming_sidecar,
};
let ciphertext = enc.data_to_upload;
// Bytes so each retry/resume attempt slices with a refcount bump instead of
// copying the whole (multi-MB) ciphertext per attempt.
let ciphertext = bytes::Bytes::from(enc.data_to_upload);

upload_media_with_retry(
crypto,
Expand All @@ -375,7 +377,7 @@ impl Client {
|| async { self.invalidate_media_conn().await },
|request| async move { self.http_client.execute(request).await },
|request, offset, _remaining| {
let body = ciphertext[offset as usize..].to_vec();
let body = ciphertext.slice(offset as usize..);
async move { self.http_client.execute(request.with_body(body)).await }
},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn spawn_qr_autoresponder_http(
url: url.clone(),
method: "POST".into(),
headers: HashMap::new(),
body: Some(code.as_bytes().to_vec()),
body: Some(code.as_bytes().to_vec().into()),
};
match http.execute(req).await {
Ok(resp) if (200..300).contains(&resp.status_code) => return,
Expand Down
6 changes: 3 additions & 3 deletions wacore/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct HttpRequest {
pub url: String,
pub method: String, // "GET" or "POST"
pub headers: HashMap<String, String>,
pub body: Option<Vec<u8>>,
pub body: Option<Bytes>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Convert direct HttpRequest bodies to Bytes

When the full workspace is checked, tests/e2e/src/lib.rs still constructs HttpRequest { body: Some(code.as_bytes().to_vec()) }; after this public field changes to Option<Bytes>, that crate no longer type-checks. The patch updates the same direct construction in examples/benchmark.rs but misses the e2e helper, so cargo check --all/cargo test --all fail before any tests run.

Useful? React with 👍 / 👎.

}

impl HttpRequest {
Expand All @@ -105,8 +105,8 @@ impl HttpRequest {
self
}

pub fn with_body(mut self, body: Vec<u8>) -> Self {
self.body = Some(body);
pub fn with_body(mut self, body: impl Into<Bytes>) -> Self {
self.body = Some(body.into());
self
}
}
Expand Down
Loading