From d40276c0f081c2cc1ebc8b63ad6075daf0f6dff0 Mon Sep 17 00:00:00 2001 From: Victor <59261226+VictorBulba@users.noreply.github.com> Date: Thu, 7 Oct 2021 22:04:18 +0300 Subject: [PATCH] wasm: add missing `as_bytes` method to `Body` implementation (#1270) --- src/wasm/body.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wasm/body.rs b/src/wasm/body.rs index 1c0b6af..9fd72a3 100644 --- a/src/wasm/body.rs +++ b/src/wasm/body.rs @@ -24,6 +24,17 @@ enum Inner { } impl Body { + /// Returns a reference to the internal data of the `Body`. + /// + /// `None` is returned, if the underlying data is a multipart form. + #[inline] + pub fn as_bytes(&self) -> Option<&[u8]> { + match &self.inner { + Inner::Bytes(bytes) => Some(bytes.as_ref()), + #[cfg(feature = "multipart")] + Inner::Multipart(_) => None, + } + } pub(crate) fn to_js_value(&self) -> crate::Result { match &self.inner { Inner::Bytes(body_bytes) => {