Skip to content

Commit

Permalink
Fix parsing responses with no CRs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed May 8, 2021
1 parent 5c385a9 commit 7370673
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ impl<'h, 'b> Response<'h, 'b> {
bytes.slice();
self.reason = Some("");
},
b'\n' => self.reason = Some(""),
b'\n' => {
bytes.slice();
self.reason = Some("");
}
_ => return Err(Error::Status),
}

Expand Down
33 changes: 33 additions & 0 deletions tests/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ macro_rules! req {
)
}

macro_rules! res {
($name:ident, $buf:expr, |$arg:ident| $body:expr) => {
res! {$name, $buf, Ok(Status::Complete($buf.len())), |$arg| $body }
};
($name:ident, $buf:expr, $len:expr, |$arg:ident| $body:expr) => {
#[test]
fn $name() {
let mut headers = [EMPTY_HEADER; NUM_OF_HEADERS];
let mut res = Response::new(&mut headers[..]);
let status = res.parse($buf.as_ref());
assert_eq!(status, $len);
closure(res);

fn closure($arg: Response) {
$body
}
}
};
}

req! {
urltest_001,
b"GET /bar;par?b HTTP/1.1\r\nHost: foo\r\n\r\n",
Expand Down Expand Up @@ -3691,3 +3711,16 @@ req! {
assert_eq!(req.headers[0].value, b"gfwsl.geforce.com");
}
}

res! {
response_nocr,
b"HTTP/1.0 200\nContent-type: text/html\n\n",
|res| {
assert_eq!(res.version.unwrap(), 0);
assert_eq!(res.code.unwrap(), 200);
assert_eq!(res.reason.unwrap(), "");
assert_eq!(res.headers.len(), 1);
assert_eq!(res.headers[0].name, "Content-type");
assert_eq!(res.headers[0].value, b"text/html");
}
}

0 comments on commit 7370673

Please sign in to comment.