content limited and bogus chunk

This commit is contained in:
Martin Algesten
2018-06-11 21:59:37 +02:00
parent 5be3aef553
commit 4ca0914f9a
3 changed files with 85 additions and 2 deletions

42
src/test/body_read.rs Normal file
View File

@@ -0,0 +1,42 @@
use std::io::Read;
use test;
use super::super::*;
#[test]
fn transfer_encoding_bogus() {
test::set_handler("/transfer_encoding_bogus", |_req, _url| {
test::make_stream(
200,
"OK",
vec![
"transfer-encoding: bogus", // whatever it says here, we should chunk
],
"3\r\nhel\r\nb\r\nlo world!!!\r\n0\r\n\r\n"
.to_string()
.into_bytes(),
)
});
let resp = get("test://host/transfer_encoding_bogus").call();
let mut reader = resp.into_reader();
let mut text = String::new();
reader.read_to_string(&mut text).unwrap();
assert_eq!(text, "hello world!!!");
}
#[test]
fn content_length_limited() {
test::set_handler("/content_length_limited", |_req, _url| {
test::make_stream(
200,
"OK",
vec!["Content-Length: 4"],
"abcdefgh".to_string().into_bytes(),
)
});
let resp = get("test://host/content_length_limited").call();
let mut reader = resp.into_reader();
let mut text = String::new();
reader.read_to_string(&mut text).unwrap();
assert_eq!(text, "abcd");
}