in src/connection.rs [667:697]
fn test_try_read_invalid_request() {
// Invalid request.
let (mut sender, receiver) = UnixStream::pair().unwrap();
receiver.set_nonblocking(true).expect("Can't modify socket");
let mut conn = HttpConnection::new(receiver);
sender
.write_all(
b"PATCH http://localhost/home HTTP/1.1\r\n\
Expect: 100-continue\r\n\
Transfer-Encoding: chunked\r\n",
)
.unwrap();
for i in 0..40 {
sender.write_all(b"Custom-Header-Testing: 1").unwrap();
sender.write_all(i.to_string().as_bytes()).unwrap();
sender.write_all(b"\r\n").unwrap();
}
sender
.write_all(b"Content-Length: alpha\r\n\r\nthis is not\n\r\na json \nbody")
.unwrap();
assert!(conn.try_read().is_ok());
let request_error = conn.try_read().unwrap_err();
assert_eq!(
request_error,
ConnectionError::ParseError(RequestError::HeaderError(HttpHeaderError::InvalidValue(
"Content-Length".to_string(),
" alpha".to_string()
)))
);
}