Skip to content

Commit

Permalink
fix parse error when no status text. close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Mar 30, 2019
1 parent 889988b commit d4d68ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,13 @@ fn parse_status_line(line: &str) -> Result<((usize, usize), u16), Error> {
let index1 = http_version.len();

let status = split.next().ok_or_else(|| Error::BadStatus)?;
if status.len() < 3 {
if status.len() < 2 {
return Err(Error::BadStatus);
}
let index2 = index1 + status.len();

let status = status.parse::<u16>().map_err(|_| Error::BadStatus)?;

let status_text = split.next().ok_or_else(|| Error::BadStatus)?;
if status_text.is_empty() {
return Err(Error::BadStatus);
}

Ok(((index1, index2), status))
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,15 @@ fn non_ascii_header() {
assert_eq!(resp.status(), 500);
assert_eq!(resp.status_text(), "Bad Header");
}

#[test]
pub fn no_status_text() {
// this one doesn't return the status text
// let resp = get("https://www.okex.com/api/spot/v3/products")
test::set_handler("/no_status_text", |_unit| {
test::make_response(200, "", vec![], vec![])
});
let resp = get("test://host/no_status_text").call();
assert!(resp.ok());
assert_eq!(resp.status(), 200);
}

0 comments on commit d4d68ae

Please sign in to comment.