forked from kent/consciousness
http: add HttpResponse::bytes() for binary downloads
Mirror of text(), but returns raw Bytes without lossy UTF-8 conversion. Needed by the Telegram channel to fetch photo files. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
91c8451f5c
commit
a075e30557
1 changed files with 8 additions and 0 deletions
|
|
@ -154,6 +154,14 @@ impl HttpResponse {
|
|||
Ok(String::from_utf8_lossy(&bytes).into_owned())
|
||||
}
|
||||
|
||||
/// Read the entire body as raw bytes (for binary downloads).
|
||||
pub async fn bytes(self) -> Result<Bytes> {
|
||||
let bytes = self.body.collect().await
|
||||
.context("reading response body")?
|
||||
.to_bytes();
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
/// Read the entire body and deserialize as JSON.
|
||||
pub async fn json<T: serde::de::DeserializeOwned>(self) -> Result<T> {
|
||||
let bytes = self.body.collect().await
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue