Skip to content

Commit

Permalink
fix(http): fix encoding when buffer is full
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jul 17, 2017
1 parent d6da3f7 commit fc5b9cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/http/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ mod tests {

#[test]
fn test_conn_body_write_length() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::init();
let _: Result<(), ()> = future::lazy(|| {
let io = AsyncIo::new_buf(vec![], 0);
let mut conn = Conn::<_, http::Chunk, ServerTransaction>::new(io, Default::default());
Expand Down
5 changes: 4 additions & 1 deletion src/http/h1/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ impl Encoder {
chunked.encode(w, msg)
},
Kind::Length(ref mut remaining) => {
if msg.is_empty() {
return Ok(0);
}
let n = {
let max = cmp::min(*remaining as usize, msg.len());
trace!("sized write, len = {}", max);
trace!("sized write, len = {}, remaining = {}", max, remaining);
let slice = &msg[..max];

try!(w.write_atomic(&[slice]))
Expand Down
7 changes: 6 additions & 1 deletion src/http/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {

impl<T: Write> Write for Buffered<T> {
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
Ok(self.write_buf.buffer(data))
let n = self.write_buf.buffer(data);
if n == 0 {
Err(io::Error::from(io::ErrorKind::WouldBlock))
} else {
Ok(n)
}
}

fn flush(&mut self) -> io::Result<()> {
Expand Down

0 comments on commit fc5b9cc

Please sign in to comment.