From 3373847a14e69969e02bc7347f4f5f808432a040 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 16 Jul 2018 00:40:22 +0600 Subject: [PATCH] allocate buffer for request payload extractors --- .travis.yml | 2 +- src/httpmessage.rs | 6 +++--- src/json.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67cd9d38a..54a86aa7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ script: fi - | if [[ "$TRAVIS_RUST_VERSION" == "stable" ]]; then - RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin + RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install -f cargo-tarpaulin cargo tarpaulin --features="alpn,tls" --out Xml --no-count bash <(curl -s https://codecov.io/bash) echo "Uploaded code coverage" diff --git a/src/httpmessage.rs b/src/httpmessage.rs index 4da0163e5..5db2f075b 100644 --- a/src/httpmessage.rs +++ b/src/httpmessage.rs @@ -286,7 +286,7 @@ impl Readlines { fn err(req: &T, err: ReadlinesError) -> Self { Readlines { stream: req.payload(), - buff: BytesMut::with_capacity(262_144), + buff: BytesMut::new(), limit: 262_144, checked_buff: true, encoding: UTF_8, @@ -472,7 +472,7 @@ where .take() .expect("Can not be used second time") .from_err() - .fold(BytesMut::new(), move |mut body, chunk| { + .fold(BytesMut::with_capacity(8192), move |mut body, chunk| { if (body.len() + chunk.len()) > limit { Err(PayloadError::Overflow) } else { @@ -581,7 +581,7 @@ where .take() .expect("UrlEncoded could not be used second time") .from_err() - .fold(BytesMut::new(), move |mut body, chunk| { + .fold(BytesMut::with_capacity(8192), move |mut body, chunk| { if (body.len() + chunk.len()) > limit { Err(UrlencodedError::Overflow) } else { diff --git a/src/json.rs b/src/json.rs index 485d0b3e4..c76aeaa7d 100644 --- a/src/json.rs +++ b/src/json.rs @@ -320,7 +320,7 @@ impl Future for JsonBod .take() .expect("JsonBody could not be used second time") .from_err() - .fold(BytesMut::new(), move |mut body, chunk| { + .fold(BytesMut::with_capacity(8192), move |mut body, chunk| { if (body.len() + chunk.len()) > limit { Err(JsonPayloadError::Overflow) } else {