Make OutputPage's mechanism for gathering Vary headers reusable
authorCatrope <roan.kattouw@gmail.com>
Fri, 1 Jun 2012 10:23:53 +0000 (03:23 -0700)
committerChad Horohoe <chadh@wikimedia.org>
Tue, 3 Jul 2012 13:32:13 +0000 (09:32 -0400)
Maybe WebResponse would be a better place for this, but this'll work for
now.

* Add getVaryHeader() to get the serialized version of $mVaryHeader.
* Remove 'Cookie' from the initializer, and add it explicitly later
** This allows reuse by code that doesn't want 'Cookie' in there

Change-Id: Ifa8f74a21f832154b05e54ced95b9f9eb6052fcd

includes/OutputPage.php

index 35b2f38..4a45175 100644 (file)
@@ -237,7 +237,6 @@ class OutputPage extends ContextSource {
        private $mFollowPolicy = 'follow';
        private $mVaryHeader = array(
                'Accept-Encoding' => array( 'list-contains=gzip' ),
-               'Cookie' => null
        );
 
        /**
@@ -1722,6 +1721,16 @@ class OutputPage extends ContextSource {
                $this->mVaryHeader[$header] = array_unique( (array)$this->mVaryHeader[$header] );
        }
 
+       /**
+        * Return a Vary: header on which to vary caches. Based on the keys of $mVaryHeader,
+        * such as Accept-Encoding or Cookie
+        * 
+        * @return String
+        */
+       public function getVaryHeader() {
+               return 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) );
+       }
+
        /**
         * Get a complete X-Vary-Options header
         *
@@ -1834,11 +1843,12 @@ class OutputPage extends ContextSource {
                        $response->header( "ETag: $this->mETag" );
                }
 
+               $this->addVaryHeader( 'Cookie' );
                $this->addAcceptLanguage();
 
                # don't serve compressed data to clients who can't handle it
                # maintain different caches for logged-in users and non-logged in ones
-               $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ) );
+               $response->header( $this->getVaryHeader() );
 
                if ( $wgUseXVO ) {
                        # Add an X-Vary-Options header for Squid with Wikimedia patches