fix parse error when no status text. close #4
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user