ResponseValue could expose Content-Length (#123)

This commit is contained in:
Joshua M. Clulow 2022-07-14 22:34:50 -07:00 committed by GitHub
parent 144ef6b9f3
commit 6ca5670819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -127,6 +127,16 @@ impl<T> ResponseValue<T> {
&self.headers
}
/// Get the parsed value of the Content-Length header, if present and valid.
pub fn content_length(&self) -> Option<u64> {
self.headers
.get(reqwest::header::CONTENT_LENGTH)?
.to_str()
.ok()?
.parse::<u64>()
.ok()
}
#[doc(hidden)]
pub fn map<U: std::fmt::Debug, F, E>(
self,