diff --git a/gen/storage1/src/client.rs b/gen/storage1/src/client.rs index 432859888e..b9d1824143 100644 --- a/gen/storage1/src/client.rs +++ b/gen/storage1/src/client.rs @@ -1,5 +1,3 @@ -// COPY OF 'src/rust/api/client.rs' -// DO NOT EDIT use std::error; use std::fmt::{self, Display}; use std::io::{self, Cursor, Read, Seek, SeekFrom, Write}; @@ -405,7 +403,7 @@ impl<'a> MultiPartReader<'a> { pub fn mime_type(&self) -> Mime { Mime( TopLevel::Multipart, - SubLevel::Ext("Related".to_string()), + SubLevel::Ext("related".to_string()), vec![( Attr::Ext("boundary".to_string()), Value::Ext(BOUNDARY.to_string()), @@ -449,9 +447,11 @@ impl<'a> Read for MultiPartReader<'a> { (n, true, _) if n > 0 => { let (headers, reader) = self.raw_parts.remove(0); 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, @@ -459,7 +459,8 @@ impl<'a> Read for MultiPartReader<'a> { .iter() .map(|(k, v)| format!("{}: {}", k, v.to_str().unwrap())) .join(LINE_ENDING), - LINE_ENDING + LINE_ENDING, + LINE_ENDING, )) .unwrap(); c.seek(SeekFrom::Start(0)).unwrap(); @@ -482,7 +483,7 @@ impl<'a> Read for MultiPartReader<'a> { // before clearing the last part, we will add the boundary that // will be written last self.last_part_boundary = Some(Cursor::new( - format!("{}--{}--", LINE_ENDING, BOUNDARY).into_bytes(), + format!("{}--{}--{}", LINE_ENDING, BOUNDARY, LINE_ENDING).into_bytes(), )) } // We are depleted - this can trigger the next part to come in @@ -696,8 +697,9 @@ impl<'a, A> ResumableUploadHelper<'a, A> { _ => MIN_CHUNK_SIZE, }; - self.reader.seek(SeekFrom::Start(start)).unwrap(); loop { + self.reader.seek(SeekFrom::Start(start)).unwrap(); + let request_size = match self.content_length - start { rs if rs > chunk_size => chunk_size, rs => rs, @@ -713,7 +715,6 @@ impl<'a, A> ResumableUploadHelper<'a, A> { }), total_length: self.content_length, }; - start += request_size; if self.delegate.cancel_chunk_upload(&range_header) { return None; } @@ -732,6 +733,8 @@ impl<'a, A> ResumableUploadHelper<'a, A> { .await; match res { Ok(res) => { + start += request_size; + if res.status() == StatusCode::PERMANENT_REDIRECT { continue; }