mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
fix: Actix server fn redirect()
duplicate Location
headers (#1326)
This commit is contained in:
parent
3cdcc85c87
commit
576bb078f7
1 changed files with 21 additions and 17 deletions
|
@ -223,18 +223,21 @@ pub fn handle_server_fns_with_context(
|
|||
let res_options =
|
||||
use_context::<ResponseOptions>(cx).unwrap();
|
||||
|
||||
let mut res: HttpResponseBuilder;
|
||||
let mut res: HttpResponseBuilder =
|
||||
HttpResponse::Ok();
|
||||
let res_parts = res_options.0.write();
|
||||
|
||||
if accept_header == Some("application/json")
|
||||
|| accept_header
|
||||
== Some("application/x-www-form-urlencoded")
|
||||
|| accept_header == Some("application/cbor")
|
||||
// if accept_header isn't set to one of these, it's a form submit
|
||||
// redirect back to the referrer if not redirect has been set
|
||||
if accept_header != Some("application/json")
|
||||
&& accept_header
|
||||
!= Some("application/x-www-form-urlencoded")
|
||||
&& accept_header != Some("application/cbor")
|
||||
{
|
||||
res = HttpResponse::Ok();
|
||||
}
|
||||
// otherwise, it's probably a <form> submit or something: redirect back to the referrer
|
||||
else {
|
||||
// Location will already be set if redirect() has been used
|
||||
let has_location_set =
|
||||
res_parts.headers.get("Location").is_some();
|
||||
if !has_location_set {
|
||||
let referer = req
|
||||
.headers()
|
||||
.get("Referer")
|
||||
|
@ -243,6 +246,7 @@ pub fn handle_server_fns_with_context(
|
|||
res = HttpResponse::SeeOther();
|
||||
res.insert_header(("Location", referer))
|
||||
.content_type("application/json");
|
||||
}
|
||||
};
|
||||
// Override StatusCode if it was set in a Resource or Element
|
||||
if let Some(status) = res_parts.status {
|
||||
|
|
Loading…
Reference in a new issue