Skip to content

Commit

Permalink
Merge pull request #537 from paolobarbolini/drop-itertools
Browse files Browse the repository at this point in the history
Drop dependency on itertools
  • Loading branch information
Byron authored Feb 1, 2025
2 parents 6674c6c + 4ce346e commit 68c883e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion google-apis-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
23 changes: 13 additions & 10 deletions google-apis-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -414,22 +413,26 @@ 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())
.map_err(|err| std::io::Error::other(err))?;
}

let mut c = Cursor::new(Vec::<u8>::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));
Expand Down

0 comments on commit 68c883e

Please sign in to comment.