silverstripe / silverstripe-sharedraftcontent

Share draft page content with non-CMS users
BSD 3-Clause "New" or "Revised" License
21 stars 28 forks source link

Disable HTTP caches on preview links #88

Closed chillu closed 6 years ago

chillu commented 6 years ago

Using new core API, see https://github.com/silverstripe/silverstripe-framework/pull/8086

Note that this release line already requires SilverStripe 3.7 or higher

chillu commented 6 years ago

Tested with the following approach:

composer.json

{
    "name": "cwp/cwp-installer",
    "description": "CWP Project Template",
    "license": "BSD-3-Clause",
    "require": {
        "cwp/cwp-recipe-basic": "~1.9.0@rc",
        "cwp/cwp-recipe-blog": "~1.9.0@rc",
        "cwp/starter-theme": "~1.1.1@stable",
        "silverstripe/controllerpolicy": "1.x-dev"
    },
    "require-dev": {
        "cwp/cwp-recipe-basic-dev": "^1.1@stable"
    },
    "suggest": {
        "silverstripe/textextraction": "Required for document text searching within CWP"
    },
    "config": {
        "process-timeout": 900
    },
    "extra": {
        "branch-alias": {
            "1.x-dev": "1.9.x-dev"
        }
    },
    "prefer-stable": true,
    "minimum-stability": "dev"
}
define('SS_ENVIRONMENT_TYPE', 'live');
class Page_Controller extends BasePage_Controller {

    public function init()
    {
        parent::init();

        HTTPCacheControl::singleton()->enableCache();
    }
}
curl -I http://cwp1-installer.vagrant/about-us
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 18 Jul 2018 10:06:16 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
Vary: X-Requested-With,X-Forwarded-Protocol
Last-Modified: Tue, 17 Jul 2018 01:33:09 GMT
ETag: "32c42955d988e0728697769d84f3df1f"
Cache-Control: must-revalidate

Preview link:

curl -I http://cwp1-installer.vagrant/preview/69a8f38668e314ac/f62633d610aaf12a
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 18 Jul 2018 10:07:17 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
Set-Cookie: PHPSESSID=63ab53d5rantldsqthc9pv24o3; expires=Wed, 18-Jul-2018 11:07:17 GMT; Max-Age=3600; path=/; HttpOnly
Set-Cookie: PHPSESSID=63ab53d5rantldsqthc9pv24o3; expires=Wed, 18-Jul-2018 11:07:17 GMT; Max-Age=3600; path=/; httponly
Vary: X-Requested-With,X-Forwarded-Protocol
Last-Modified: Wed, 18 Jul 2018 10:03:24 GMT
ETag: "c5ccdea41921c421793ebd42d0e38dcd"
Cache-Control: must-revalidate

Preview link with pull request:

curl -I http://cwp1-installer.vagrant/preview/69a8f38668e314ac/f62633d610aaf12a
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 18 Jul 2018 10:09:07 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
Set-Cookie: PHPSESSID=l0oi6f17i6jsc7iu4ga8odgq32; expires=Wed, 18-Jul-2018 11:09:07 GMT; Max-Age=3600; path=/; HttpOnly
Set-Cookie: PHPSESSID=l0oi6f17i6jsc7iu4ga8odgq32; expires=Wed, 18-Jul-2018 11:09:07 GMT; Max-Age=3600; path=/; httponly
Vary: X-Requested-With,X-Forwarded-Protocol
Last-Modified: Wed, 18 Jul 2018 10:03:24 GMT
Cache-Control: no-cache, no-store, must-revalidate
robbieaverill commented 6 years ago

Actually I'm going to cherry-pick this back into 1.3.x as a patch, which is already for 3.7.x

robbieaverill commented 6 years ago

Ok merged and tagged in 1.3.1, we'll get this into CWP 1.9 as a hotfix