Skip to content

Commit 837681c

Browse files
committed
Expose bytes to the Response object
This patch exposes the `Response::bytes`, which is basically a wrapper on reqwest::Response::bytes().
1 parent 82d32de commit 837681c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

elasticsearch/src/http/response.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121
error::Error as ClientError,
2222
http::{headers::HeaderMap, Method, StatusCode, Url},
2323
};
24+
use bytes::Bytes;
2425
use serde::{
2526
de,
2627
de::{DeserializeOwned, MapAccess, Visitor},
@@ -128,6 +129,14 @@ impl Response {
128129
Ok(body)
129130
}
130131

132+
/// Asynchronously reads the response body as bytes
133+
///
134+
/// Reading the response body consumes `self`
135+
pub async fn bytes(self) -> Result<Bytes, ClientError> {
136+
let bytes: Bytes = self.response.bytes().await?;
137+
Ok(bytes)
138+
}
139+
131140
/// Gets the request URL
132141
pub fn url(&self) -> &Url {
133142
self.response.url()

0 commit comments

Comments
 (0)