mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-13 21:19:05 +01:00
fix(mbuild): upload size now taken properly
Previously, it would query the size from the wrong dict and obtain the value 0 all the time. This would have made every upload fail with `UploadSizeLimitExeeded`. Now we obtain the actual size limit, and will ignore it if unset/0 for some reason. Patch += 1
This commit is contained in:
@@ -274,6 +274,7 @@ impl<'a> MultiPartReader<'a> {
|
||||
/// Add a new part to the queue of parts to be read on the first `read` call.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// `headers` - identifying the body of the part. It's similar to the header
|
||||
/// in an ordinary single-part call, and should thus contain the
|
||||
/// same information.
|
||||
@@ -281,9 +282,6 @@ impl<'a> MultiPartReader<'a> {
|
||||
/// `size` - the amount of bytes provided by the reader. It will be put onto the header as
|
||||
/// content-size.
|
||||
/// `mime` - It will be put onto the content type
|
||||
/// # Panics
|
||||
///
|
||||
/// If this method is called after the first `read` call, it will panic
|
||||
pub fn add_part(&mut self, reader: &'a mut Read, size: u64, mime_type: Mime) -> &mut MultiPartReader<'a> {
|
||||
let mut headers = Headers::new();
|
||||
headers.set(ContentType(mime_type));
|
||||
@@ -462,22 +460,17 @@ impl Header for RangeResponseHeader {
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> Option<RangeResponseHeader> {
|
||||
match raw {
|
||||
[ref v] => {
|
||||
if let Ok(s) = std::str::from_utf8(v) {
|
||||
const PREFIX: &'static str = "bytes=";
|
||||
if s.starts_with(PREFIX) {
|
||||
let c: Chunk = match FromStr::from_str(&s[PREFIX.len()..]) {
|
||||
Ok(c) => c,
|
||||
_ => return None
|
||||
};
|
||||
if let [ref v] = raw {
|
||||
if let Ok(s) = std::str::from_utf8(v) {
|
||||
const PREFIX: &'static str = "bytes=";
|
||||
if s.starts_with(PREFIX) {
|
||||
if let Ok(c) = <Chunk as FromStr>::from_str(&s[PREFIX.len()..]) {
|
||||
return Some(RangeResponseHeader(c))
|
||||
}
|
||||
}
|
||||
None
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,13 +550,13 @@ impl<'a, NC, A> ResumableUploadHelper<'a, NC, A>
|
||||
_ => MIN_CHUNK_SIZE
|
||||
};
|
||||
|
||||
self.reader.seek(SeekFrom::Start(start)).unwrap();
|
||||
loop {
|
||||
let request_size = match self.content_length - start {
|
||||
rs if rs > chunk_size => chunk_size,
|
||||
rs => rs
|
||||
};
|
||||
|
||||
self.reader.seek(SeekFrom::Start(start)).unwrap();
|
||||
let mut section_reader = self.reader.take(request_size);
|
||||
let range_header = ContentRange {
|
||||
range: Some(Chunk {first: start, last: start + request_size - 1}),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file was generated automatically from 'src/mako/lib.rs.mako'
|
||||
// DO NOT EDIT !
|
||||
|
||||
//! This documentation was generated from *mirror* crate version *0.1.0+20150220*, where *20150220* is the exact revision of the *mirror:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.0*.
|
||||
//! This documentation was generated from *mirror* crate version *0.1.1+20150220*, where *20150220* is the exact revision of the *mirror:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.1*.
|
||||
//!
|
||||
//! Everything else about the *mirror* *v1* API can be found at the
|
||||
//! [official documentation site](https://developers.google.com/glass).
|
||||
@@ -328,7 +328,7 @@ impl<'a, C, NC, A> Mirror<C, NC, A>
|
||||
Mirror {
|
||||
client: RefCell::new(client),
|
||||
auth: RefCell::new(authenticator),
|
||||
_user_agent: "google-api-rust-client/0.1.0".to_string(),
|
||||
_user_agent: "google-api-rust-client/0.1.1".to_string(),
|
||||
_m: PhantomData
|
||||
}
|
||||
}
|
||||
@@ -353,7 +353,7 @@ impl<'a, C, NC, A> Mirror<C, NC, A>
|
||||
}
|
||||
|
||||
/// Set the user-agent header field to use in all requests to the server.
|
||||
/// It defaults to `google-api-rust-client/0.1.0`.
|
||||
/// It defaults to `google-api-rust-client/0.1.1`.
|
||||
///
|
||||
/// Returns the previously set user-agent.
|
||||
pub fn user_agent(&mut self, agent_name: String) -> String {
|
||||
@@ -2835,8 +2835,8 @@ impl<'a, C, NC, A> TimelineInsertCall<'a, C, NC, A> where NC: hyper::net::Networ
|
||||
mp_reader.reserve_exact(2);
|
||||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||||
if size > 0 {
|
||||
return Result::UploadSizeLimitExceeded(size, 0)
|
||||
if size > 10485760 {
|
||||
return Result::UploadSizeLimitExceeded(size, 10485760)
|
||||
}
|
||||
mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone())
|
||||
.add_part(&mut reader, size, reader_mime_type.clone());
|
||||
@@ -2885,8 +2885,8 @@ impl<'a, C, NC, A> TimelineInsertCall<'a, C, NC, A> where NC: hyper::net::Networ
|
||||
if protocol == "resumable" {
|
||||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||||
if size > 0 {
|
||||
return Result::UploadSizeLimitExceeded(size, 0)
|
||||
if size > 10485760 {
|
||||
return Result::UploadSizeLimitExceeded(size, 10485760)
|
||||
}
|
||||
let mut client = &mut *self.hub.client.borrow_mut();
|
||||
let upload_result = {
|
||||
@@ -3725,8 +3725,8 @@ impl<'a, C, NC, A> TimelineAttachmentInsertCall<'a, C, NC, A> where NC: hyper::n
|
||||
if protocol == "simple" {
|
||||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||||
if size > 0 {
|
||||
return Result::UploadSizeLimitExceeded(size, 0)
|
||||
if size > 10485760 {
|
||||
return Result::UploadSizeLimitExceeded(size, 10485760)
|
||||
}
|
||||
req = req.header(ContentType(reader_mime_type.clone()))
|
||||
.header(ContentLength(size))
|
||||
@@ -3766,8 +3766,8 @@ impl<'a, C, NC, A> TimelineAttachmentInsertCall<'a, C, NC, A> where NC: hyper::n
|
||||
if protocol == "resumable" {
|
||||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||||
if size > 0 {
|
||||
return Result::UploadSizeLimitExceeded(size, 0)
|
||||
if size > 10485760 {
|
||||
return Result::UploadSizeLimitExceeded(size, 10485760)
|
||||
}
|
||||
let mut client = &mut *self.hub.client.borrow_mut();
|
||||
let upload_result = {
|
||||
@@ -4529,8 +4529,8 @@ impl<'a, C, NC, A> TimelineUpdateCall<'a, C, NC, A> where NC: hyper::net::Networ
|
||||
mp_reader.reserve_exact(2);
|
||||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||||
if size > 0 {
|
||||
return Result::UploadSizeLimitExceeded(size, 0)
|
||||
if size > 10485760 {
|
||||
return Result::UploadSizeLimitExceeded(size, 10485760)
|
||||
}
|
||||
mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone())
|
||||
.add_part(&mut reader, size, reader_mime_type.clone());
|
||||
@@ -4579,8 +4579,8 @@ impl<'a, C, NC, A> TimelineUpdateCall<'a, C, NC, A> where NC: hyper::net::Networ
|
||||
if protocol == "resumable" {
|
||||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||||
if size > 0 {
|
||||
return Result::UploadSizeLimitExceeded(size, 0)
|
||||
if size > 10485760 {
|
||||
return Result::UploadSizeLimitExceeded(size, 10485760)
|
||||
}
|
||||
let mut client = &mut *self.hub.client.borrow_mut();
|
||||
let upload_result = {
|
||||
|
||||
Reference in New Issue
Block a user