fix(server): don't redirect error responses from #[get] server functions (#5429)
The post-handler redirect logic was unconditionally converting responses to 302 Found when the request had Accept: text/html and a Referer header. This overwrote error status codes (4xx, 5xx), making it impossible to return errors from #[get] endpoints accessed via browser navigation. Add a response.status().is_success() guard so only successful responses get the Post/Redirect/Get treatment. Fixes #5428
This commit is contained in:
1 parent
e5b9c39f4e
commit
45442af41d
1 file changed
+5
-3
@@ -113,9 +113,11 @@ impl ServerFunction {
|
||||
response.headers_mut().extend(headers);
|
||||
}
|
||||
|
||||
// if it accepts text/html (i.e., is a plain form post) and doesn't already have a
|
||||
// Location set, then redirect to Referer
|
||||
if accepts_html {
|
||||
// If the response is successful and accepts text/html (i.e., is a
|
||||
// plain form post) and doesn't already have a Location set, then
|
||||
// redirect to Referer. Only redirect on success so that error
|
||||
// responses (4xx, 5xx) propagate correctly to the client.
|
||||
if accepts_html && response.status().is_success() {
|
||||
if let Some(referrer) = referrer {
|
||||
let has_location = response.headers().get(LOCATION).is_some();
|
||||
if !has_location {
|
||||
|
||||
Reference in new issue
Block a user