diff --git a/server_fn/src/codec/cbor.rs b/server_fn/src/codec/cbor.rs index a5a91c811..051bc266c 100644 --- a/server_fn/src/codec/cbor.rs +++ b/server_fn/src/codec/cbor.rs @@ -29,12 +29,7 @@ where let mut buffer: Vec = Vec::new(); ciborium::ser::into_writer(&self, &mut buffer) .map_err(|e| ServerFnError::Serialization(e.to_string()))?; - Request::try_new_post_bytes( - path, - accepts, - Cbor::CONTENT_TYPE, - Bytes::from(buffer), - ) + Request::try_new_post_bytes(path, accepts, Cbor::CONTENT_TYPE, &buffer) } } diff --git a/server_fn/src/codec/rkyv.rs b/server_fn/src/codec/rkyv.rs index 2d9753ad1..ab5ed08ae 100644 --- a/server_fn/src/codec/rkyv.rs +++ b/server_fn/src/codec/rkyv.rs @@ -35,8 +35,12 @@ where ) -> Result> { let encoded = rkyv::to_bytes::(&self) .map_err(|e| ServerFnError::Serialization(e.to_string()))?; - let bytes = Bytes::copy_from_slice(encoded.as_ref()); - Request::try_new_post_bytes(path, accepts, Rkyv::CONTENT_TYPE, bytes) + Request::try_new_post_bytes( + path, + accepts, + Rkyv::CONTENT_TYPE, + encoded.as_ref(), + ) } } @@ -50,7 +54,7 @@ where { async fn from_req(req: Request) -> Result> { let body_bytes = req.try_into_bytes().await?; - rkyv::from_bytes::(body_bytes.as_ref()) + rkyv::from_bytes::(&body_bytes) .map_err(|e| ServerFnError::Args(e.to_string())) } } diff --git a/server_fn/src/request/browser.rs b/server_fn/src/request/browser.rs index b2fda95ff..4e5db475a 100644 --- a/server_fn/src/request/browser.rs +++ b/server_fn/src/request/browser.rs @@ -78,13 +78,12 @@ impl ClientReq for BrowserRequest { path: &str, accepts: &str, content_type: &str, - body: Bytes, + body: &[u8], ) -> Result> { let server_url = get_server_url(); let mut url = String::with_capacity(server_url.len() + path.len()); url.push_str(server_url); url.push_str(path); - let body: &[u8] = &body; let body = Uint8Array::from(body).buffer(); Ok(Self(SendWrapper::new( Request::post(&url) diff --git a/server_fn/src/request/mod.rs b/server_fn/src/request/mod.rs index e1a008520..75d8ad17f 100644 --- a/server_fn/src/request/mod.rs +++ b/server_fn/src/request/mod.rs @@ -45,7 +45,7 @@ where path: &str, content_type: &str, accepts: &str, - body: Bytes, + body: &[u8], ) -> Result>; /// Attempts to construct a new `POST` request with form data as the body. diff --git a/server_fn/src/request/reqwest.rs b/server_fn/src/request/reqwest.rs index 012985470..db20f2873 100644 --- a/server_fn/src/request/reqwest.rs +++ b/server_fn/src/request/reqwest.rs @@ -56,14 +56,14 @@ impl ClientReq for Request { path: &str, accepts: &str, content_type: &str, - body: Bytes, + body: &[u8], ) -> Result> { let url = format!("{}{}", get_server_url(), path); CLIENT .post(url) .header(CONTENT_TYPE, content_type) .header(ACCEPT, accepts) - .body(body) + .body(body.to_owned()) .build() .map_err(|e| ServerFnError::Request(e.to_string())) }