r93818 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93817‎ | r93818 | r93819 >
Date:12:00, 3 August 2011
Author:catrope
Status:ok
Tags:
Comment:
Introduce $wgVaryOnXFPToAPI which sends Vary: X-Forwarded-Proto (and the appropriate XVO, if needed) on cached API requests. This effectively splits the API cache between HTTP and HTTPS for people with an HTTPS termination setup in front of a caching proxy (like, say, WMF)
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMain.php
@@ -399,6 +399,7 @@
400400 }
401401
402402 protected function sendCacheHeaders() {
 403+ global $wgUseXVO, $wgOut, $wgVaryOnXFPForAPI;
403404 $response = $this->getRequest()->response();
404405
405406 if ( $this->mCacheMode == 'private' ) {
@@ -407,9 +408,12 @@
408409 }
409410
410411 if ( $this->mCacheMode == 'anon-public-user-private' ) {
411 - global $wgUseXVO, $wgOut;
412 - $response->header( 'Vary: Accept-Encoding, Cookie' );
 412+ $xfp = $wgVaryOnXFPForAPI ? ', X-Forwarded-Proto' : '';
 413+ $response->header( 'Vary: Accept-Encoding, Cookie' . $xfp );
413414 if ( $wgUseXVO ) {
 415+ if ( $wgVaryOnXFPForAPI ) {
 416+ $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
 417+ }
414418 $response->header( $wgOut->getXVO() );
415419 if ( $wgOut->haveCacheVaryCookies() ) {
416420 // Logged in, mark this request private
@@ -424,6 +428,15 @@
425429 return;
426430 } // else no XVO and anonymous, send public headers below
427431 }
 432+
 433+ // Send public headers
 434+ if ( $wgVaryOnXFPForAPI ) {
 435+ $response->header( 'Vary: Accept-Encoding, X-Forwarded-Proto' );
 436+ if ( $wgUseXVO ) {
 437+ // Bleeeeegh. Our header setting system sucks
 438+ $response->header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip, X-Forwarded-Proto' );
 439+ }
 440+ }
428441
429442 // If nobody called setCacheMaxAge(), use the (s)maxage parameters
430443 if ( !isset( $this->mCacheControl['s-maxage'] ) ) {
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1739,6 +1739,13 @@
17401740 /** Send X-Vary-Options header for better caching (requires patched Squid) */
17411741 $wgUseXVO = false;
17421742
 1743+/** Add X-Forwarded-Proto to the Vary and X-Vary-Options headers for API
 1744+ * requests. Use this if you have an SSL termination setup and want to split
 1745+ * the cache between HTTP and HTTPS for API requests. This does not affect
 1746+ * 'regular' requests.
 1747+ */
 1748+$wgVaryOnXFPForAPI = false;
 1749+
17431750 /**
17441751 * Internal server name as known to Squid, if different. Example:
17451752 * <code>

Follow-up revisions

RevisionCommit summaryAuthorDate
r938901.17wmf1: MFT rest of protocol-relative URL fixes and API cache splitting sup...catrope15:02, 4 August 2011
r94425Add RELEASE-NOTES for r93818 and r94155. Adding to the 1.18 file since they'r...catrope18:33, 13 August 2011
r94472MFT to REL1_18:...hashar19:43, 14 August 2011
r98755Rename $wgVaryOnXFPForAPI (introduced in r93818) to $wgVaryOnXFP and extend i...catrope13:15, 3 October 2011

Status & tagging log