Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(h1): ending close-delimited body should close #2322

Merged
merged 1 commit into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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