r93890 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93889‎ | r93890 | r93891 >
Date:15:02, 4 August 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT rest of protocol-relative URL fixes and API cache splitting support from r93818, r93820, r93821, r93822
Modified paths:
  • /branches/wmf/1.17wmf1/includes/DefaultSettings.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/HttpFunctions.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/User.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/WebRequest.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiMain.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/filerepo/ForeignAPIRepo.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/libs/CSSMin.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/parser/CoreParserFunctions.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/resourceloader/ResourceLoaderFileModule.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/User.php
@@ -3052,7 +3052,9 @@
30533053 str_replace(
30543054 '$1',
30553055 "Special:$page/$token",
3056 - $wgArticlePath ) );
 3056+ $wgArticlePath ),
 3057+ PROTO_HTTP
 3058+ );
30573059 }
30583060
30593061 /**
Property changes on: branches/wmf/1.17wmf1/includes/User.php
___________________________________________________________________
Modified: svn:mergeinfo
30603062 Merged /trunk/phase3/includes/User.php:r93820-93822
Index: branches/wmf/1.17wmf1/includes/parser/CoreParserFunctions.php
@@ -647,7 +647,7 @@
648648 // ... and we can
649649 if ( $mto && !$mto->isError() ) {
650650 // ... change the URL to point to a thumbnail.
651 - $url = wfExpandUrl( $mto->getUrl() );
 651+ $url = wfExpandUrl( $mto->getUrl(), PROTO_RELATIVE );
652652 }
653653 }
654654 if ( $option == 'nowiki' ) {
Index: branches/wmf/1.17wmf1/includes/filerepo/ForeignAPIRepo.php
@@ -355,7 +355,7 @@
356356 public static function httpGet( $url, $timeout = 'default', $options = array() ) {
357357 $options['timeout'] = $timeout;
358358 /* Http::get */
359 - $url = wfExpandUrl( $url );
 359+ $url = wfExpandUrl( $url, PROTO_HTTP );
360360 wfDebug( "ForeignAPIRepo: HTTP GET: $url\n" );
361361 $options['method'] = "GET";
362362
Index: branches/wmf/1.17wmf1/includes/api/ApiMain.php
@@ -381,15 +381,19 @@
382382 }
383383
384384 protected function sendCacheHeaders() {
 385+ global $wgUseXVO, $wgOut, $wgVaryOnXFPForAPI;
385386 if ( $this->mCacheMode == 'private' ) {
386387 header( 'Cache-Control: private' );
387388 return;
388389 }
389390
390391 if ( $this->mCacheMode == 'anon-public-user-private' ) {
391 - global $wgUseXVO, $wgOut;
392 - header( 'Vary: Accept-Encoding, Cookie' );
 392+ $xfp = $wgVaryOnXFPForAPI ? ', X-Forwarded-Proto' : '';
 393+ header( 'Vary: Accept-Encoding, Cookie' . $xfp );
393394 if ( $wgUseXVO ) {
 395+ if ( $wgVaryOnXFPForAPI ) {
 396+ $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
 397+ }
394398 header( $wgOut->getXVO() );
395399 if ( $wgOut->haveCacheVaryCookies() ) {
396400 // Logged in, mark this request private
@@ -404,6 +408,15 @@
405409 return;
406410 } // else no XVO and anonymous, send public headers below
407411 }
 412+
 413+ // Send public headers
 414+ if ( $wgVaryOnXFPForAPI ) {
 415+ header( 'Vary: Accept-Encoding, X-Forwarded-Proto' );
 416+ if ( $wgUseXVO ) {
 417+ // Bleeeeegh. Our header setting system sucks
 418+ header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip, X-Forwarded-Proto' );
 419+ }
 420+ }
408421
409422 // If nobody called setCacheMaxAge(), use the (s)maxage parameters
410423 if ( !isset( $this->mCacheControl['s-maxage'] ) ) {
Index: branches/wmf/1.17wmf1/includes/WebRequest.php
@@ -552,6 +552,8 @@
553553
554554 /**
555555 * Return the request URI with the canonical service and hostname.
 556+ *
 557+ * NOTE: This will output a protocol-relative URL if $wgServer is protocol-relative
556558 *
557559 * @return String
558560 */
Property changes on: branches/wmf/1.17wmf1/includes/WebRequest.php
___________________________________________________________________
Modified: svn:mergeinfo
559561 Merged /trunk/phase3/includes/WebRequest.php:r93820-93822
Index: branches/wmf/1.17wmf1/includes/resourceloader/ResourceLoaderFileModule.php
@@ -202,8 +202,9 @@
203203 break;
204204 }
205205 }
206 - // Make sure the remote base path is a complete valid url
207 - $this->remoteBasePath = wfExpandUrl( $this->remoteBasePath );
 206+ // Make sure the remote base path is a complete valid URL,
 207+ // but possibly protocol-relative to avoid cache pollution
 208+ $this->remoteBasePath = wfExpandUrl( $this->remoteBasePath, PROTO_RELATIVE );
208209 }
209210
210211 /**
Index: branches/wmf/1.17wmf1/includes/libs/CSSMin.php
@@ -131,7 +131,7 @@
132132 // to absolute URLs but otherwise left alone
133133 if ( $match['file'][0] !== '' && $match['file'][0][0] === '/' ) {
134134 // Replace the file path with an expanded URL
135 - $source = substr_replace( $source, wfExpandUrl( $match['file'][0] ),
 135+ $source = substr_replace( $source, wfExpandUrl( $match['file'][0], PROTO_RELATIVE ),
136136 $match['file'][1], strlen( $match['file'][0] )
137137 );
138138 // Move the offset to the end of the match, leaving it alone
Index: branches/wmf/1.17wmf1/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>
Property changes on: branches/wmf/1.17wmf1/includes/DefaultSettings.php
___________________________________________________________________
Modified: svn:mergeinfo
17461753 Merged /trunk/phase3/includes/DefaultSettings.php:r93820-93822
Index: branches/wmf/1.17wmf1/includes/HttpFunctions.php
@@ -14,7 +14,7 @@
1515 * Perform an HTTP request
1616 *
1717 * @param $method String: HTTP method. Usually GET/POST
18 - * @param $url String: full URL to act on
 18+ * @param $url String: full URL to act on. If protocol-relative, will be expanded to an http:// URL
1919 * @param $options Array: options to pass to MWHttpRequest object.
2020 * Possible keys for the array:
2121 * - timeout Timeout length in seconds
@@ -32,7 +32,7 @@
3333 * @return Mixed: (bool)false on failure or a string on success
3434 */
3535 public static function request( $method, $url, $options = array() ) {
36 - $url = wfExpandUrl( $url );
 36+ $url = wfExpandUrl( $url, PROTO_HTTP );
3737 wfDebug( "HTTP: $method: $url\n" );
3838 $options['method'] = strtoupper( $method );
3939

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93818Introduce $wgVaryOnXFPToAPI which sends Vary: X-Forwarded-Proto (and the appr...catrope12:00, 3 August 2011
r93820Some random URL protocol forcing for protocol-relative URLscatrope12:58, 3 August 2011
r93821Fix r93820: PROT_ -> PROTO_catrope13:11, 3 August 2011
r93822Fix syntax error in r93820catrope13:12, 3 August 2011

Status & tagging log