From 7185a5a181a89c308cf9130fdf0347423e962a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Mon, 10 Aug 2020 23:47:12 +0100 Subject: [PATCH] fix(server): update proto::h1::end_body to return Result<()> fix #2263 --- src/proto/h1/conn.rs | 8 +++++--- src/proto/h1/dispatch.rs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index a3d6a537ce..52cbaf7fe1 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -12,6 +12,7 @@ use super::{Decoder, Encode, EncodedBuf, Encoder, Http1Transaction, ParseContext use crate::common::{task, Pin, Poll, Unpin}; use crate::headers::connection_keep_alive; use crate::proto::{BodyLength, DecodedLength, MessageHead}; +use crate::Result; const H2_PREFACE: &[u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"; @@ -584,7 +585,7 @@ where self.state.writing = state; } - pub fn end_body(&mut self) { + pub fn end_body(&mut self) -> Result<()> { debug_assert!(self.can_write_body()); let state = match self.state.writing { @@ -601,13 +602,14 @@ where Writing::KeepAlive } } - Err(_not_eof) => Writing::Closed, + Err(_not_eof) => return Err(crate::Error::new_closed()), } } - _ => return, + _ => return Ok(()), }; self.state.writing = state; + Ok(()) } // When we get a parse error, depending on what side we are, we might be able diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index a878651f0b..c0e407bf59 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -338,7 +338,7 @@ where *clear_body = true; if chunk.remaining() == 0 { trace!("discarding empty chunk"); - self.conn.end_body(); + self.conn.end_body()?; } else { self.conn.write_body_and_end(chunk); } @@ -351,7 +351,7 @@ where } } else { *clear_body = true; - self.conn.end_body(); + self.conn.end_body()?; } } else { return Poll::Pending;