From 3efa4f2b12219412cdabf8535e03974b94f71af5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 8 May 2015 12:38:59 +0200 Subject: [PATCH] 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 ! --- etc/api/type-api.yaml | 1 + etc/api/type-cli.yaml | 1 - src/mako/api/lib.rs.mako | 1 + src/mako/api/lib/mbuild.mako | 13 ++++++++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/etc/api/type-api.yaml b/etc/api/type-api.yaml index 5d45aa55679..7f988c0f893 100644 --- a/etc/api/type-api.yaml +++ b/etc/api/type-api.yaml @@ -27,3 +27,4 @@ cargo: - url = "*" - serde = ">= 0.3.0" - serde_macros = "*" + - json-tools = "*" diff --git a/etc/api/type-cli.yaml b/etc/api/type-cli.yaml index 783c3e74cf8..82f29a17726 100644 --- a/etc/api/type-cli.yaml +++ b/etc/api/type-cli.yaml @@ -31,4 +31,3 @@ cargo: - serde = ">= 0.3.0" - serde_macros = "*" - clap = "*" - - json-tools = "*" diff --git a/src/mako/api/lib.rs.mako b/src/mako/api/lib.rs.mako index cbdc56c5b50..b485218f395 100644 --- a/src/mako/api/lib.rs.mako +++ b/src/mako/api/lib.rs.mako @@ -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; diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 518e9c80328..3c62bb1cb90 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -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::${'>'}() + ) + }; let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap(); request_value_reader.seek(io::SeekFrom::Start(0)).unwrap(); % endif