Skip to content

Commit

Permalink
fix(server): update proto::h1::end_body to return Result<()> fix #2263
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Aug 10, 2020
1 parent 3de81c8 commit 8662dfa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tokio::io::{AsyncRead, AsyncWrite};

use super::io::Buffered;
use super::{Decoder, Encode, EncodedBuf, Encoder, Http1Transaction, ParseContext, Wants};
use crate::Result;
use crate::common::{task, Pin, Poll, Unpin};
use crate::headers::connection_keep_alive;
use crate::proto::{BodyLength, DecodedLength, MessageHead};
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -351,7 +351,7 @@ where
}
} else {
*clear_body = true;
self.conn.end_body();
self.conn.end_body()?;
}
} else {
return Poll::Pending;
Expand Down

0 comments on commit 8662dfa

Please sign in to comment.