[pbs-devel] [PATCH proxmox 1/5] proxmox-http: add method to share full body as contiguous bytes

Christian Ebner c.ebner at proxmox.com
Mon Aug 25 12:32:44 CEST 2025


While already possible to get the body contents as bytes slice,
exposing it as `Bytes` object has the advantage to be able to
efficiently clone the body when a shared reference is not possible,
e.g. for request cloning.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 proxmox-http/src/body.rs | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/proxmox-http/src/body.rs b/proxmox-http/src/body.rs
index 3eb17355..a1dade27 100644
--- a/proxmox-http/src/body.rs
+++ b/proxmox-http/src/body.rs
@@ -35,6 +35,14 @@ impl Body {
         }
     }
 
+    /// Returns the body contents as `Bytes` it is a "full" body, None otherwise.
+    pub fn bytes(&self) -> Option<Bytes> {
+        match self.inner {
+            InnerBody::Full(ref bytes) => Some(bytes.clone()),
+            InnerBody::Streaming(_) => None,
+        }
+    }
+
     pub fn wrap_stream<S>(stream: S) -> Body
     where
         S: futures::stream::TryStream + Send + 'static,
-- 
2.47.2





More information about the pbs-devel mailing list