diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index fc1eea56..26a670e9 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,11 +1,13 @@ # Changes -## [1.0.0-alpha.5] - 2019-12-xx +## [1.0.0-alpha.5] - 2019-12-09 ### Fixed * Check `Upgrade` service readiness before calling it +* Fix buffer remaining capacity calcualtion + ### Changed * Websockets: Ping and Pong should have binary data #1049 diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index f42604be..c3b228e7 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http" -version = "1.0.0-alpha.4" +version = "1.0.0-alpha.5" authors = ["Nikolay Kim "] description = "Actix http primitives" readme = "README.md" diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 3bcf1137..1147465b 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -8,7 +8,7 @@ use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed, FramedParts}; use actix_rt::time::{delay_until, Delay, Instant}; use actix_service::Service; use bitflags::bitflags; -use bytes::{BufMut, BytesMut}; +use bytes::BytesMut; use log::{error, trace}; use crate::body::{Body, BodySize, MessageBody, ResponseBody}; @@ -751,8 +751,10 @@ where }; loop { - if inner.write_buf.remaining_mut() < LW_BUFFER_SIZE { - inner.write_buf.reserve(HW_BUFFER_SIZE); + let remaining = + inner.write_buf.capacity() - inner.write_buf.len(); + if remaining < LW_BUFFER_SIZE { + inner.write_buf.reserve(HW_BUFFER_SIZE - remaining); } let result = inner.poll_response(cx)?; let drain = result == PollResponse::DrainWriteBuf; @@ -863,8 +865,9 @@ where { let mut read_some = false; loop { - if buf.remaining_mut() < LW_BUFFER_SIZE { - buf.reserve(HW_BUFFER_SIZE); + let remaining = buf.capacity() - buf.len(); + if remaining < LW_BUFFER_SIZE { + buf.reserve(HW_BUFFER_SIZE - remaining); } match read(cx, io, buf) {