Add Response::text() to async Client

This commit is contained in:
messense
2019-06-23 14:39:41 +08:00
committed by Sean McArthur
parent a3cd3633d8
commit c5f2bf6c32
2 changed files with 95 additions and 0 deletions

View File

@@ -29,6 +29,42 @@ fn gzip_single_byte_chunks() {
gzip_case(10, 1);
}
#[test]
fn response_text() {
let _ = env_logger::try_init();
let server = server! {
request: b"\
GET /text HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
\r\n\
",
response: b"\
HTTP/1.1 200 OK\r\n\
Content-Length: 5\r\n\
\r\n\
Hello\
"
};
let mut rt = Runtime::new().expect("new rt");
let client = Client::new();
let res_future = client.get(&format!("http://{}/text", server.addr()))
.send()
.and_then(|mut res| res.text())
.and_then(|text| {
assert_eq!("Hello", text);
Ok(())
});
rt.block_on(res_future).unwrap();
}
#[test]
fn multipart() {
let _ = env_logger::try_init();