Skip to content

Commit

Permalink
Merge pull request #699 from kaedroho/fix/698
Browse files Browse the repository at this point in the history
fix(server): Removed check for GET/HEAD request when parsing body
  • Loading branch information
seanmonstar committed Nov 30, 2015
2 parents 3f1b13c + 1077440 commit d1f4a8b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/server/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::Duration;
use buffer::BufReader;
use net::NetworkStream;
use version::{HttpVersion};
use method::Method::{self, Get, Head};
use method::Method;
use header::{Headers, ContentLength, TransferEncoding};
use http::h1::{self, Incoming, HttpReader};
use http::h1::HttpReader::{SizedReader, ChunkedReader, EmptyReader};
Expand Down Expand Up @@ -41,9 +41,7 @@ impl<'a, 'b: 'a> Request<'a, 'b> {
debug!("Request Line: {:?} {:?} {:?}", method, uri, version);
debug!("{:?}", headers);

let body = if method == Get || method == Head {
EmptyReader(stream)
} else if headers.has::<ContentLength>() {
let body = if headers.has::<ContentLength>() {
match headers.get::<ContentLength>() {
Some(&ContentLength(len)) => SizedReader(stream, len),
None => unreachable!()
Expand Down Expand Up @@ -159,6 +157,24 @@ mod tests {
assert_eq!(read_to_string(req).unwrap(), "".to_owned());
}

#[test]
fn test_get_with_body() {
let mut mock = MockStream::with_input(b"\
GET / HTTP/1.1\r\n\
Host: example.domain\r\n\
Content-Length: 19\r\n\
\r\n\
I'm a good request.\r\n\
");

// FIXME: Use Type ascription
let mock: &mut NetworkStream = &mut mock;
let mut stream = BufReader::new(mock);

let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
assert_eq!(read_to_string(req).unwrap(), "I'm a good request.".to_owned());
}

#[test]
fn test_head_empty_body() {
let mut mock = MockStream::with_input(b"\
Expand Down

0 comments on commit d1f4a8b

Please sign in to comment.