From 63376de793de38d7dbfae2ce61303c26fea92a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n?= Date: Thu, 21 May 2020 19:46:56 +0200 Subject: [PATCH] Implement `Response::content_length` for `wasm32` (#863) --- src/wasm/response.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/wasm/response.rs b/src/wasm/response.rs index 765606c..0f77c49 100644 --- a/src/wasm/response.rs +++ b/src/wasm/response.rs @@ -45,6 +45,22 @@ impl Response { self.http.headers_mut() } + /// Get the content-length of this response, if known. + /// + /// Reasons it may not be known: + /// + /// - The server didn't send a `content-length` header. + /// - The response is compressed and automatically decoded (thus changing + // the actual decoded length). + pub fn content_length(&self) -> Option { + self.headers() + .get(http::header::CONTENT_LENGTH)? + .to_str() + .ok()? + .parse() + .ok() + } + /// Get the final `Url` of this `Response`. #[inline] pub fn url(&self) -> &Url {