Skip to content

Commit 68c883e

Browse files
authored
Merge pull request #537 from paolobarbolini/drop-itertools
Drop dependency on itertools
2 parents 6674c6c + 4ce346e commit 68c883e

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

google-apis-common/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ http = "1"
2020
http-body-util = "0.1"
2121
hyper = { version = "1", features = ["client", "http2"] }
2222
hyper-util = { version = "0.1", features = ["client-legacy", "http2"] }
23-
itertools = "0.13"
2423
mime = "0.3"
2524
percent-encoding = "2"
2625
serde = { version = "1", features = ["derive"] }

google-apis-common/src/lib.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::time::Duration;
1313
use hyper::header::{HeaderMap, AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, USER_AGENT};
1414
use hyper::Method;
1515
use hyper::StatusCode;
16-
use itertools::Itertools;
1716
use mime::Mime;
1817
use tokio::time::sleep;
1918

@@ -414,22 +413,26 @@ impl Read for MultiPartReader<'_> {
414413
}
415414
(0, true, true) => return Ok(0),
416415
(n, true, _) if n > 0 => {
416+
use std::fmt::Write as _;
417417
let (headers, reader) = self.raw_parts.remove(0);
418+
419+
let mut encoded_headers = String::new();
420+
for (k, v) in &headers {
421+
if !encoded_headers.is_empty() {
422+
encoded_headers.push_str(LINE_ENDING);
423+
}
424+
425+
write!(encoded_headers, "{}: {}", k, v.to_str().unwrap())
426+
.map_err(|err| std::io::Error::other(err))?;
427+
}
428+
418429
let mut c = Cursor::new(Vec::<u8>::new());
419430
//TODO: The first line ending should be omitted for the first part,
420431
// fortunately Google's API serves don't seem to mind.
421432
(write!(
422433
&mut c,
423434
"{}--{}{}{}{}{}",
424-
LINE_ENDING,
425-
BOUNDARY,
426-
LINE_ENDING,
427-
headers
428-
.iter()
429-
.map(|(k, v)| format!("{}: {}", k, v.to_str().unwrap()))
430-
.join(LINE_ENDING),
431-
LINE_ENDING,
432-
LINE_ENDING,
435+
LINE_ENDING, BOUNDARY, LINE_ENDING, encoded_headers, LINE_ENDING, LINE_ENDING,
433436
))?;
434437
c.rewind()?;
435438
self.current_part = Some((c, reader));

0 commit comments

Comments
 (0)