In ApiMain, gather Vary headers in OutputPage
authorCatrope <roan.kattouw@gmail.com>
Fri, 1 Jun 2012 11:11:32 +0000 (04:11 -0700)
committerReedy <reedy@wikimedia.org>
Thu, 5 Jul 2012 20:29:31 +0000 (21:29 +0100)
Using OutputPage for this rather than something like WebResponse
probably isn't optimal, but it's a lot nicer than the mess we had
before.

Change-Id: I9dce06d3eb69dd7952eafc6c94ead2ad5ad88792

includes/api/ApiMain.php

index 30e9fb6..3a9698d 100644 (file)
@@ -405,6 +405,11 @@ class ApiMain extends ApiBase {
        protected function sendCacheHeaders() {
                global $wgUseXVO, $wgVaryOnXFP;
                $response = $this->getRequest()->response();
+               $out = $this->getOutput();
+
+               if ( $wgVaryOnXFP ) {
+                       $out->addVaryHeader( 'X-Forwarded-Proto' );
+               }
 
                if ( $this->mCacheMode == 'private' ) {
                        $response->header( 'Cache-Control: private' );
@@ -412,13 +417,9 @@ class ApiMain extends ApiBase {
                }
 
                if ( $this->mCacheMode == 'anon-public-user-private' ) {
-                       $xfp = $wgVaryOnXFP ? ', X-Forwarded-Proto' : '';
-                       $response->header( 'Vary: Accept-Encoding, Cookie' . $xfp );
+                       $out->addVaryHeader( 'Cookie' );
+                       $response->header( $out->getVaryHeader() );
                        if ( $wgUseXVO ) {
-                               $out = $this->getOutput();
-                               if ( $wgVaryOnXFP ) {
-                                       $out->addVaryHeader( 'X-Forwarded-Proto' );
-                               }
                                $response->header( $out->getXVO() );
                                if ( $out->haveCacheVaryCookies() ) {
                                        // Logged in, mark this request private
@@ -435,12 +436,9 @@ class ApiMain extends ApiBase {
                }
 
                // Send public headers
-               if ( $wgVaryOnXFP ) {
-                       $response->header( 'Vary: Accept-Encoding, X-Forwarded-Proto' );
-                       if ( $wgUseXVO ) {
-                               // Bleeeeegh. Our header setting system sucks
-                               $response->header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip, X-Forwarded-Proto' );
-                       }
+               $response->header( $out->getVaryHeader() );
+               if ( $wgUseXVO ) {
+                       $response->header( $out->getXVO() );
                }
 
                // If nobody called setCacheMaxAge(), use the (s)maxage parameters