allow server functions to read request and modify responce

This commit is contained in:
Evan Almloff committed 2023-04-29 17:04:54 -05:00
1 parent 581a4648de
commit 7ff5d356d5
14 files changed
+387 -159

No files matched your search

@@ -56,11 +56,12 @@ fn app(cx: Scope<AppProps>) -> Element {
button {
onclick: move |_| {
to_owned![text];
let sc = cx.sc();
async move {
if let Ok(data) = get_server_data().await {
println!("Client received: {}", data);
text.set(data.clone());
post_server_data(data).await.unwrap();
post_server_data(sc, data).await.unwrap();
}
}
},
@@ -71,8 +72,12 @@ fn app(cx: Scope<AppProps>) -> Element {
}
#[server(PostServerData)]
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
async fn post_server_data(cx: DioxusServerContext, data: String) -> Result<(), ServerFnError> {
// The server context contains information about the current request and allows you to modify the response.
cx.responce_headers_mut()
.insert("Set-Cookie", "foo=bar".parse().unwrap());
println!("Server received: {}", data);
println!("Request parts are {:?}", cx.request_parts());
Ok(())
}