Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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().
  • Loading branch information...
commit d4b8db27afddc49f5ff37b25ed13490f6ec5c608 1 parent bbfa54c
Ingo Schommer chillu authored
Showing with 27 additions and 0 deletions.
  1. +27 −0 admin/code/LeftAndMain.php
27 admin/code/LeftAndMain.php
View
@@ -358,6 +358,17 @@ function redirect($url, $code=302) {
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 @@ function mark($node) {
}
}
+/**
+ * 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;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.