fix(API): filter null values of requrest structs

Some servers, like youtube, reject null values possibly thanks to
the reliance on parts. Now we are filtering them (in a very inefficient,
but working way), which seems to be fine with the servers.

Effectively, we seem to be able now to upload videos ... .

More testing required !
This commit is contained in:
Sebastian Thiel
2015-05-08 12:38:59 +02:00
parent 3fe2732a01
commit 3efa4f2b12
4 changed files with 14 additions and 2 deletions

View File

@@ -27,3 +27,4 @@ cargo:
- url = "*"
- serde = ">= 0.3.0"
- serde_macros = "*"
- json-tools = "*"

View File

@@ -31,4 +31,3 @@ cargo:
- serde = ">= 0.3.0"
- serde_macros = "*"
- clap = "*"
- json-tools = "*"

View File

@@ -37,6 +37,7 @@ extern crate serde;
extern crate yup_oauth2 as oauth2;
extern crate mime;
extern crate url;
extern crate json_tools;
mod cmn;

View File

@@ -663,7 +663,18 @@ else {
% if request_value:
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
let mut request_value_reader = io::Cursor::new(json::to_vec(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}));
let mut request_value_reader =
{
let json_cache = json::to_string(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}).unwrap();
io::Cursor::new(json_tools::TokenReader::new(
json_tools::FilterTypedKeyValuePairs::new(
json_tools::Lexer::new(
json_cache.bytes(),
json_tools::BufferType::Span),
json_tools::TokenType::Null),
Some(&json_cache)).bytes().filter_map(|v|v.ok()).collect::${'<Vec<u8>>'}()
)
};
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
% endif