From 693df72500f6416fbeb028f828794ee901a01f81 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sat, 1 Feb 2025 08:32:44 +0000 Subject: [PATCH 1/2] Drop dependency on itertools --- google-apis-common/Cargo.toml | 1 - google-apis-common/src/lib.rs | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/google-apis-common/Cargo.toml b/google-apis-common/Cargo.toml index 89efc64c3b..600b5dd60d 100644 --- a/google-apis-common/Cargo.toml +++ b/google-apis-common/Cargo.toml @@ -20,7 +20,6 @@ http = "1" http-body-util = "0.1" hyper = { version = "1", features = ["client", "http2"] } hyper-util = { version = "0.1", features = ["client-legacy", "http2"] } -itertools = "0.13" mime = "0.3" percent-encoding = "2" serde = { version = "1", features = ["derive"] } diff --git a/google-apis-common/src/lib.rs b/google-apis-common/src/lib.rs index 77df7f50c6..73b8f57b0b 100644 --- a/google-apis-common/src/lib.rs +++ b/google-apis-common/src/lib.rs @@ -13,7 +13,6 @@ use std::time::Duration; use hyper::header::{HeaderMap, AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, USER_AGENT}; use hyper::Method; use hyper::StatusCode; -use itertools::Itertools; use mime::Mime; use tokio::time::sleep; @@ -414,22 +413,25 @@ impl Read for MultiPartReader<'_> { } (0, true, true) => return Ok(0), (n, true, _) if n > 0 => { + use std::fmt::Write as _; let (headers, reader) = self.raw_parts.remove(0); + + let mut encoded_headers = String::new(); + for (k, v) in &headers { + if !encoded_headers.is_empty() { + encoded_headers.push_str(LINE_ENDING); + } + + write!(encoded_headers, "{}: {}", k, v.to_str().unwrap()).unwrap(); + } + let mut c = Cursor::new(Vec::::new()); //TODO: The first line ending should be omitted for the first part, // fortunately Google's API serves don't seem to mind. (write!( &mut c, "{}--{}{}{}{}{}", - LINE_ENDING, - BOUNDARY, - LINE_ENDING, - headers - .iter() - .map(|(k, v)| format!("{}: {}", k, v.to_str().unwrap())) - .join(LINE_ENDING), - LINE_ENDING, - LINE_ENDING, + LINE_ENDING, BOUNDARY, LINE_ENDING, encoded_headers, LINE_ENDING, LINE_ENDING, ))?; c.rewind()?; self.current_part = Some((c, reader)); From 4ce346ec976aca85faaaa99049d52f0fc726dd5a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 1 Feb 2025 14:02:51 +0100 Subject: [PATCH 2/2] avoid extra unwrap even though it's unlikely to panic. --- google-apis-common/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-apis-common/src/lib.rs b/google-apis-common/src/lib.rs index 73b8f57b0b..ccd6d21c3a 100644 --- a/google-apis-common/src/lib.rs +++ b/google-apis-common/src/lib.rs @@ -422,7 +422,8 @@ impl Read for MultiPartReader<'_> { encoded_headers.push_str(LINE_ENDING); } - write!(encoded_headers, "{}: {}", k, v.to_str().unwrap()).unwrap(); + write!(encoded_headers, "{}: {}", k, v.to_str().unwrap()) + .map_err(|err| std::io::Error::other(err))?; } let mut c = Cursor::new(Vec::::new());