Skip to content

Commit ca211a9

Browse files
committed
Check for correct content-length header for all json responses
1 parent f7a3dda commit ca211a9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/tests/util/response.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ impl<T> Response<T> {
4040
#[track_caller]
4141
// TODO: Rename to into_json()
4242
pub fn json(mut self) -> Value {
43-
assert_eq!(
44-
self.response
45-
.headers()
46-
.get(header::CONTENT_TYPE)
47-
.expect("Missing content-type header"),
48-
"application/json; charset=utf-8"
49-
);
5043
json(&mut self.response)
5144
}
5245

@@ -96,6 +89,23 @@ where
9689
File(_) => unimplemented!(),
9790
};
9891

92+
assert_eq!(
93+
r.headers()
94+
.get(header::CONTENT_TYPE)
95+
.expect("Missing content-type header"),
96+
"application/json; charset=utf-8"
97+
);
98+
99+
assert_eq!(
100+
r.headers()
101+
.get(header::CONTENT_LENGTH)
102+
.expect("Missing content-length header")
103+
.to_str()
104+
.unwrap()
105+
.parse(),
106+
Ok(body.len())
107+
);
108+
99109
let s = std::str::from_utf8(&body).unwrap();
100110
match serde_json::from_str(s) {
101111
Ok(t) => t,

0 commit comments

Comments
 (0)