Revert "use &[u8] instead of Bytes for requests"

This reverts commit e179db1d42.
This commit is contained in:
Greg Johnston 2024-01-19 14:37:03 -05:00
parent 25120c0e9f
commit a519859a66
5 changed files with 14 additions and 12 deletions

View file

@ -29,7 +29,12 @@ where
let mut buffer: Vec<u8> = 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, &buffer)
Request::try_new_post_bytes(
path,
accepts,
Cbor::CONTENT_TYPE,
Bytes::from(buffer),
)
}
}

View file

@ -35,12 +35,8 @@ where
) -> Result<Request, ServerFnError<CustErr>> {
let encoded = rkyv::to_bytes::<T, 1024>(&self)
.map_err(|e| ServerFnError::Serialization(e.to_string()))?;
Request::try_new_post_bytes(
path,
accepts,
Rkyv::CONTENT_TYPE,
encoded.as_ref(),
)
let bytes = Bytes::copy_from_slice(encoded.as_ref());
Request::try_new_post_bytes(path, accepts, Rkyv::CONTENT_TYPE, bytes)
}
}
@ -54,7 +50,7 @@ where
{
async fn from_req(req: Request) -> Result<Self, ServerFnError<CustErr>> {
let body_bytes = req.try_into_bytes().await?;
rkyv::from_bytes::<T>(&body_bytes)
rkyv::from_bytes::<T>(body_bytes.as_ref())
.map_err(|e| ServerFnError::Args(e.to_string()))
}
}

View file

@ -78,12 +78,13 @@ impl<CustErr> ClientReq<CustErr> for BrowserRequest {
path: &str,
accepts: &str,
content_type: &str,
body: &[u8],
body: Bytes,
) -> Result<Self, ServerFnError<CustErr>> {
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)

View file

@ -45,7 +45,7 @@ where
path: &str,
content_type: &str,
accepts: &str,
body: &[u8],
body: Bytes,
) -> Result<Self, ServerFnError<CustErr>>;
/// Attempts to construct a new `POST` request with form data as the body.

View file

@ -56,14 +56,14 @@ impl<CustErr> ClientReq<CustErr> for Request {
path: &str,
accepts: &str,
content_type: &str,
body: &[u8],
body: Bytes,
) -> Result<Self, ServerFnError<CustErr>> {
let url = format!("{}{}", get_server_url(), path);
CLIENT
.post(url)
.header(CONTENT_TYPE, content_type)
.header(ACCEPT, accepts)
.body(body.to_owned())
.body(body)
.build()
.map_err(|e| ServerFnError::Request(e.to_string()))
}