Introduce $wgVaryOnXFPToAPI which sends Vary: X-Forwarded-Proto (and the appropriate...
authorRoan Kattouw <catrope@users.mediawiki.org>
Wed, 3 Aug 2011 12:00:47 +0000 (12:00 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Wed, 3 Aug 2011 12:00:47 +0000 (12:00 +0000)
includes/DefaultSettings.php
includes/api/ApiMain.php

index f75d3ec..643df90 100644 (file)
@@ -1739,6 +1739,13 @@ $wgUseESI = false;
 /** Send X-Vary-Options header for better caching (requires patched Squid) */
 $wgUseXVO = false;
 
+/** Add X-Forwarded-Proto to the Vary and X-Vary-Options headers for API
+ * requests. Use this if you have an SSL termination setup and want to split
+ * the cache between HTTP and HTTPS for API requests. This does not affect
+ * 'regular' requests.
+ */
+$wgVaryOnXFPForAPI = false;
+
 /**
  * Internal server name as known to Squid, if different. Example:
  * <code>
index c03a9e6..e45ba85 100644 (file)
@@ -399,6 +399,7 @@ class ApiMain extends ApiBase {
        }
 
        protected function sendCacheHeaders() {
+               global $wgUseXVO, $wgOut, $wgVaryOnXFPForAPI;
                $response = $this->getRequest()->response();
 
                if ( $this->mCacheMode == 'private' ) {
@@ -407,9 +408,12 @@ class ApiMain extends ApiBase {
                }
 
                if ( $this->mCacheMode == 'anon-public-user-private' ) {
-                       global $wgUseXVO, $wgOut;
-                       $response->header( 'Vary: Accept-Encoding, Cookie' );
+                       $xfp = $wgVaryOnXFPForAPI ? ', X-Forwarded-Proto' : '';
+                       $response->header( 'Vary: Accept-Encoding, Cookie' . $xfp );
                        if ( $wgUseXVO ) {
+                               if ( $wgVaryOnXFPForAPI ) {
+                                       $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
+                               }
                                $response->header( $wgOut->getXVO() );
                                if ( $wgOut->haveCacheVaryCookies() ) {
                                        // Logged in, mark this request private
@@ -424,6 +428,15 @@ class ApiMain extends ApiBase {
                                return;
                        } // else no XVO and anonymous, send public headers below
                }
+               
+               // Send public headers
+               if ( $wgVaryOnXFPForAPI ) {
+                       $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' );
+                       }
+               }
 
                // If nobody called setCacheMaxAge(), use the (s)maxage parameters
                if ( !isset( $this->mCacheControl['s-maxage'] ) ) {