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(http): keep raw reason phrase in RawStatus #498

Merged
merged 1 commit into from
May 2, 2015
Merged
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
22 changes: 19 additions & 3 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ impl<'a> TryParse for httparse::Response<'a, 'a> {
httparse::Status::Complete(len) => {
let code = res.code.unwrap();
let reason = match StatusCode::from_u16(code).canonical_reason() {
Some(reason) => Cow::Borrowed(reason),
None => Cow::Owned(res.reason.unwrap().to_owned())
Some(reason) if reason == res.reason.unwrap() => Cow::Borrowed(reason),
_ => Cow::Owned(res.reason.unwrap().to_owned())
};
httparse::Status::Complete((Incoming {
version: if res.version.unwrap() == 1 { Http11 } else { Http10 },
Expand Down Expand Up @@ -460,7 +460,7 @@ mod tests {
use buffer::BufReader;
use mock::MockStream;

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

#[test]
fn test_write_chunked() {
Expand Down Expand Up @@ -533,6 +533,22 @@ mod tests {
parse_request(&mut buf).unwrap();
}

#[test]
fn test_parse_raw_status() {
let mut raw = MockStream::with_input(b"HTTP/1.1 200 OK\r\n\r\n");
let mut buf = BufReader::new(&mut raw);
let res = parse_response(&mut buf).unwrap();

assert_eq!(res.subject.1, "OK");

let mut raw = MockStream::with_input(b"HTTP/1.1 200 Howdy\r\n\r\n");
let mut buf = BufReader::new(&mut raw);
let res = parse_response(&mut buf).unwrap();

assert_eq!(res.subject.1, "Howdy");
}


#[test]
fn test_parse_tcp_closed() {
use std::io::ErrorKind;
Expand Down