Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Guindon2019-04-02 14:40:50 +0000
committerChristopher Guindon2019-04-02 15:31:08 +0000
commit6753b96847a146d550efd7ef1c84351f706e9945 (patch)
treea1c9623c440aaeeaeca08477b532e3a7e4fe6068
parente5aa13a38b2077fa14f9487adac285670aacd7e4 (diff)
downloadeclipse.org-common-6753b96847a146d550efd7ef1c84351f706e9945.tar.gz
eclipse.org-common-6753b96847a146d550efd7ef1c84351f706e9945.tar.xz
eclipse.org-common-6753b96847a146d550efd7ef1c84351f706e9945.zip
Bug 3088 - App() should set caching headers for nginx
Caching headers are used only if the user is not logged in. Change-Id: Ic8e3b7737b155c00d3dc9cb663eb8535ec215b7d Signed-off-by: Christopher Guindon <chris.guindon@eclipse-foundation.org>
-rw-r--r--classes/themes/baseTheme.class.php17
-rw-r--r--system/app.class.php47
-rw-r--r--system/session.class.php6
3 files changed, 60 insertions, 10 deletions
diff --git a/classes/themes/baseTheme.class.php b/classes/themes/baseTheme.class.php
index a1706580..c367f612 100644
--- a/classes/themes/baseTheme.class.php
+++ b/classes/themes/baseTheme.class.php
@@ -2367,6 +2367,23 @@ EOHTML;
$this->setAttributes('body', 'hidden-cfa-button');
}
+ // Generate caching headers
+ if ($this->App->getPreventCaching()) {
+ $ts = gmdate("D, d M Y H:i:s") . " GMT";
+ header("Cache-Control: no-cache, must-revalidate");
+ header("Pragma: no-cache");
+ header("Last-Modified: ". $ts);
+ header("Expires:" . $ts);
+ }
+ else{
+ // 15 minute caching for html php pages
+ $caching_seconds = 900;
+ $ts = gmdate("D, d M Y H:i:s", time() + $caching_seconds) . " GMT";
+ header("Expires:" . $ts);
+ header("Pragma: cache");
+ header("Cache-Control: max-age=" . $caching_seconds);
+ }
+
ob_start();
switch ($this->getLayout()) {
case 'barebone':
diff --git a/system/app.class.php b/system/app.class.php
index f4d26090..5a403bad 100644
--- a/system/app.class.php
+++ b/system/app.class.php
@@ -226,6 +226,14 @@ class App {
*/
private $OutDatedMsg = "";
+
+ /**
+ * Prevent caching flag
+ *
+ * @var bool
+ */
+ private $prevent_caching = FALSE;
+
/**
* Development mode flag
*
@@ -261,6 +269,13 @@ class App {
*/
private $Messages = NULL;
+ /**
+ * Sessions()
+ *
+ * @var unknown
+ */
+ private $Session = NULL;
+
// Default constructor
function __construct() {
@@ -762,10 +777,22 @@ class App {
if (session_id() == '') {
session_start();
}
- header("Cache-Control: no-store, no-cache, private, must-revalidate, max-age=0, max-stale=0");
- header("Cache-Control: post-check=0, pre-check=0", FALSE);
- header("Pragma: no-cache");
- header("Expires: 0");
+ $this->prevent_caching = TRUE;
+ }
+
+ /**
+ * Get Prevent Caching Flag
+ *
+ * @return boolean
+ */
+ function getPreventCaching() {
+ $Session = $this->useSession();
+ $gid = $Session->getGID();
+ if (!empty($gid)) {
+ return TRUE;
+ }
+
+ return (is_bool($this->prevent_caching)) ? $this->prevent_caching : FALSE;
}
/**
@@ -1457,11 +1484,15 @@ class App {
*/
function useSession($required = "") {
require_once ($this->getBasePath() . "/system/session.class.php");
- $ssn = new Session(); // constructor calls validate
- if ($ssn->getGID() == "" && $required == "required") {
- $ssn->redirectToLogin();
+ if ($this->Session instanceof Session) {
+ return $this->Session;
+ }
+
+ $this->Session = new Session(); // constructor calls validate
+ if ($this->Session->getGID() == "" && $required == "required") {
+ $this->Session->redirectToLogin();
}
- return $ssn;
+ return $this->Session;
}
/**
diff --git a/system/session.class.php b/system/session.class.php
index 9729b279..3ef65c69 100644
--- a/system/session.class.php
+++ b/system/session.class.php
@@ -40,6 +40,8 @@ class Session {
private $login_page = "";
+ private $cookies_sent = FALSE;
+
/**
* Default constructor
*
@@ -258,10 +260,10 @@ class Session {
*/
public function setEclipseSessionCookies(){
$gid = $this->getGID();
- if (empty($gid)) {
+ if (empty($gid) || $this->cookies_sent) {
return FALSE;
}
-
+ $this->cookies_sent = TRUE;
$cookie_time = 0;
if ($this->getIsPersistent()) {
$cookie_time = time()+3600*24*7;

Back to the top