Skip to content

Commit

Permalink
Merge pull request #647 from mlalic/issue-646
Browse files Browse the repository at this point in the history
fix(http): Make sure not to lose the stream when CL is invalid
  • Loading branch information
seanmonstar committed Sep 4, 2015
2 parents 32e09a0 + a36e44a commit 1b869c4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/http/h1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ impl HttpMessage for Http11Message {
SizedReader(stream, len)
} else if headers.has::<ContentLength>() {
trace!("illegal Content-Length: {:?}", headers.get_raw("Content-Length"));
self.stream = Some(stream.into_inner());
return Err(Error::Header);
} else {
trace!("neither Transfer-Encoding nor Content-Length");
Expand Down Expand Up @@ -893,10 +894,12 @@ mod tests {
use std::error::Error;
use std::io::{self, Read, Write};


use buffer::BufReader;
use mock::MockStream;
use http::HttpMessage;

use super::{read_chunk_size, parse_request, parse_response};
use super::{read_chunk_size, parse_request, parse_response, Http11Message};

#[test]
fn test_write_chunked() {
Expand Down Expand Up @@ -987,6 +990,15 @@ mod tests {
assert_eq!(e.description(), "early eof");
}

#[test]
fn test_message_get_incoming_invalid_content_length() {
let raw = MockStream::with_input(
b"HTTP/1.1 200 OK\r\nContent-Length: asdf\r\n\r\n");
let mut msg = Http11Message::with_stream(Box::new(raw));
assert!(msg.get_incoming().is_err());
assert!(msg.close_connection().is_ok());
}

#[test]
fn test_parse_incoming() {
let mut raw = MockStream::with_input(b"GET /echo HTTP/1.1\r\nHost: hyper.rs\r\n\r\n");
Expand Down

0 comments on commit 1b869c4

Please sign in to comment.