Improved redirects: send redirect response in JSON if the request was in JSON

This commit is contained in:
Matias Griese 2021-11-12 12:08:13 +02:00
parent 061ebf06c6
commit 956ed013cf
2 changed files with 5 additions and 0 deletions

View File

@ -10,6 +10,7 @@
* Improved page cloning, added method `Page::initialize()`
* Improved `FlexObject::getChanges()`: return changed lists and arrays as whole instead of just changed keys/values
* Improved form validation JSON responses to contain list of failed fields with their error messages
* Improved redirects: send redirect response in JSON if the request was in JSON
3. [](#bugfix)
* Fixed path traversal vulnerability when using `bin/grav server`
* Fixed unescaped error messages in JSON error responses

View File

@ -464,6 +464,10 @@ class Grav extends Container
}
}
if ($uri->extension() === 'json') {
return new Response(200, ['Content-Type' => 'application/json'], json_encode(['code' => $code, 'redirect' => $url], JSON_THROW_ON_ERROR));
}
return new Response($code, ['Location' => $url]);
}