mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Marking fake LeftAndMain->redirect() responses as finished
Introduce new LeftAndMain_HTTPResponse class for this purpose, to mark a response as finished regardless of HTTP status. This is required for ajax responses which do redirects on app layer rather than HTTP (to avoid double processing). Specifically required to decorate LeftAndMain->init() in the 'translatable' module (TranslatableCMSMainExtension), which marks the response as finished through its redirect, avoiding further processing after init().
This commit is contained in:
parent
bbfa54c816
commit
d4b8db27af
@ -358,6 +358,17 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
||||
if($this->request->getHeader('X-Pjax') && !$this->response->getHeader('X-Pjax')) {
|
||||
$this->response->addHeader('X-Pjax', $this->request->getHeader('X-Pjax'));
|
||||
}
|
||||
$oldResponse = $this->response;
|
||||
$newResponse = new LeftAndMain_HTTPResponse(
|
||||
$oldResponse->getBody(),
|
||||
$oldResponse->getStatusCode(),
|
||||
$oldResponse->getStatusDescription()
|
||||
);
|
||||
foreach($oldResponse->getHeaders() as $k => $v) {
|
||||
$newResponse->addHeader($k, $v);
|
||||
}
|
||||
$newResponse->setIsFinished(true);
|
||||
$this->response = $newResponse;
|
||||
return ''; // Actual response will be re-requested by client
|
||||
} else {
|
||||
parent::redirect($url, $code);
|
||||
@ -1471,3 +1482,19 @@ class LeftAndMainMarkingFilter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow overriding finished state for faux redirects.
|
||||
*/
|
||||
class LeftAndMain_HTTPResponse extends SS_HTTPResponse {
|
||||
|
||||
protected $isFinished = false;
|
||||
|
||||
function isFinished() {
|
||||
return (parent::isFinished() || $this->isFinished);
|
||||
}
|
||||
|
||||
function setIsFinished($bool) {
|
||||
$this->isFinished = $bool;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user