Fix accept heading behavior in Axum to match Actix

This commit is contained in:
Ben Wishovich 2022-11-27 18:25:43 -08:00
parent 6c22c47bbf
commit fe5c9c6f0d
2 changed files with 8 additions and 14 deletions

View file

@ -56,9 +56,6 @@ pub async fn handle_server_fns(
.expect("couldn't spawn runtime")
.block_on({
async move {
// let body: &[u8] = &body;
println!("Body 2: {:#?}", &body);
let res = if let Some(server_fn) = server_fn_by_path(fn_name.as_str()) {
let runtime = create_runtime();
let (cx, disposer) = raw_scope_and_disposer(runtime);
@ -76,7 +73,8 @@ pub async fn handle_server_fns(
let accept_header =
headers.get("Accept").and_then(|value| value.to_str().ok());
let mut res = Response::builder();
if let Some("application/json") = accept_header {
if accept_header.is_some() {
res = res.status(StatusCode::OK);
}
// otherwise, it's probably a <form> submit or something: redirect back to the referrer

View file

@ -27,8 +27,8 @@
//!
//! ### `#[server]`
//!
//! The [`#[server]` macro](leptos::leptos_macro::server) allows you to annotate a function to
//! indicate that it should only run on the server (i.e., when you have an `ssr` feature in your
//! The [`#[server]` macro](leptos::leptos_macro::server) allows you to annotate a function to
//! indicate that it should only run on the server (i.e., when you have an `ssr` feature in your
//! crate that is enabled).
//!
//! ```rust,ignore
@ -353,9 +353,8 @@ pub async fn call_server_fn<T>(
where
T: serde::Serialize + serde::de::DeserializeOwned + Sized,
{
use ciborium::{ser::into_writer};
use ciborium::ser::into_writer;
use leptos_dom::js_sys::Uint8Array;
//use leptos_dom::log;
use serde_json::Deserializer as JSONDeserializer;
#[derive(Debug)]
@ -417,22 +416,19 @@ where
}
if enc == Encoding::Cbor {
//log!("FUNCTION RESPONSE CBOR");
let binary = resp
.binary()
.await
.map_err(|e| ServerFnError::Deserialization(e.to_string()))?;
//log!("REAL SERVER RESPONSE: {:#?}", &binary);
ciborium::de::from_reader(binary.as_slice()).map_err(|e| {
//log!("Failed to DECODE: {}", &e);
ServerFnError::Deserialization(e.to_string())
})
ciborium::de::from_reader(binary.as_slice())
.map_err(|e| ServerFnError::Deserialization(e.to_string()))
} else {
let text = resp
.text()
.await
.map_err(|e| ServerFnError::Deserialization(e.to_string()))?;
let mut deserializer = JSONDeserializer::from_str(&text);
T::deserialize(&mut deserializer).map_err(|e| ServerFnError::Deserialization(e.to_string()))
}