src/client/http_client.rs: use async for h2api_response()
This commit is contained in:
parent
c18fddf80f
commit
9edd3bf1b8
@ -1179,9 +1179,9 @@ impl H2Client {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn h2api_response(
|
async fn h2api_response(
|
||||||
response: Response<h2::RecvStream>,
|
response: Response<h2::RecvStream>,
|
||||||
) -> impl Future<Output = Result<Value, Error>> {
|
) -> Result<Value, Error> {
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
|
|
||||||
let (_head, mut body) = response.into_parts();
|
let (_head, mut body) = response.into_parts();
|
||||||
@ -1194,15 +1194,13 @@ impl H2Client {
|
|||||||
// the data from memory.
|
// the data from memory.
|
||||||
let mut release_capacity = body.release_capacity().clone();
|
let mut release_capacity = body.release_capacity().clone();
|
||||||
|
|
||||||
body
|
let mut data = Vec::new();
|
||||||
.map_ok(move |chunk| {
|
while let Some(chunk) = body.try_next().await? {
|
||||||
// Let the server send more data.
|
// Let the server send more data.
|
||||||
let _ = release_capacity.release_capacity(chunk.len());
|
let _ = release_capacity.release_capacity(chunk.len());
|
||||||
chunk
|
data.extend(chunk);
|
||||||
})
|
}
|
||||||
.try_concat()
|
|
||||||
.map_err(Error::from)
|
|
||||||
.and_then(move |data| async move {
|
|
||||||
let text = String::from_utf8(data.to_vec()).unwrap();
|
let text = String::from_utf8(data.to_vec()).unwrap();
|
||||||
if status.is_success() {
|
if status.is_success() {
|
||||||
if text.len() > 0 {
|
if text.len() > 0 {
|
||||||
@ -1219,7 +1217,6 @@ impl H2Client {
|
|||||||
} else {
|
} else {
|
||||||
bail!("HTTP Error {}: {}", status, text);
|
bail!("HTTP Error {}: {}", status, text);
|
||||||
}
|
}
|
||||||
}.boxed())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: We always encode parameters with the url
|
// Note: We always encode parameters with the url
|
||||||
|
Loading…
Reference in New Issue
Block a user