1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Utils to deal with streams data types.
use crate;
use PayloadError;
use Bytes;
use ResponseBody;
use Stream;
/// Read body from an HTTP response as string.
/// The content has to be encoded in UTF-8, otherwise
/// [`AppError::Unexpected`] is returned.
/// # Example
/// ```
/// use actix_contrib_rest::result::Result;
/// use actix_contrib_rest::stream::read_body;
/// use awc::Client;
/// use log::error;
///
/// async fn get_example() -> Result<String> {
/// let client = Client::default();
/// let mut res = client.get("http://example.com/")
/// .send()
/// .await
/// .unwrap_or_else(|e| {
/// error!("{}", e);
/// std::process::exit(1);
/// });
/// read_body(res.body()).await
/// }
/// ```
pub async