1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 14:49:20 +02:00

handle response errors

This commit is contained in:
Nikolay Kim
2018-11-21 07:49:24 -08:00
parent ab3e12f2b4
commit 1a322966ff
5 changed files with 111 additions and 50 deletions

View File

@ -445,3 +445,25 @@ fn test_body_chunked_implicit() {
let bytes = srv.block_on(response.body()).unwrap();
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
}
#[test]
fn test_response_http_error_handling() {
let mut srv = test::TestServer::with_factory(|| {
h1::H1Service::new(|_| {
let broken_header = Bytes::from_static(b"\0\0\0");
ok::<_, ()>(
Response::Ok()
.header(http::header::CONTENT_TYPE, broken_header)
.body(STR),
)
}).map(|_| ())
});
let req = srv.get().finish().unwrap();
let response = srv.send_request(req).unwrap();
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
// read response
let bytes = srv.block_on(response.body()).unwrap();
assert!(bytes.is_empty());
}