Skip to content

Commit

Permalink
Improved redirects: send redirect response in JSON if the request was…
Browse files Browse the repository at this point in the history
… in JSON
  • Loading branch information
mahagr committed Nov 12, 2021
1 parent 061ebf0 commit 956ed01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ public function getRedirectResponse($route, $code = null): ResponseInterface
}
}

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]);
}

Expand Down

0 comments on commit 956ed01

Please sign in to comment.