Skip to content

Commit

Permalink
fix(http1): ending close-delimited body should close (#2322)
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw authored Nov 6, 2020
1 parent 1b9af22 commit 71f3402
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ where
pub fn end_body(&mut self) -> Result<()> {
debug_assert!(self.can_write_body());

let mut res = Ok(());
let state = match self.state.writing {
Writing::Body(ref mut encoder) => {
// end of stream, that means we should try to eof
Expand All @@ -600,24 +601,25 @@ where
if let Some(end) = end {
self.io.buffer(end);
}
if encoder.is_last() {
if encoder.is_last() || encoder.is_close_delimited() {
Writing::Closed
} else {
Writing::KeepAlive
}
}
Err(_not_eof) => {
return Err(crate::Error::new_user_body(
res = Err(crate::Error::new_user_body(
crate::Error::new_body_write_aborted(),
))
));
Writing::Closed
}
}
}
_ => return Ok(()),
};

self.state.writing = state;
Ok(())
res
}

// When we get a parse error, depending on what side we are, we might be able
Expand Down
7 changes: 7 additions & 0 deletions src/proto/h1/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ impl Encoder {
self.is_last
}

pub fn is_close_delimited(&self) -> bool {
match self.kind {
Kind::CloseDelimited => true,
_ => false,
}
}

pub fn end<B>(&self) -> Result<Option<EncodedBuf<B>>, NotEof> {
match self.kind {
Kind::Length(0) => Ok(None),
Expand Down

0 comments on commit 71f3402

Please sign in to comment.