From 08aa4418c30cfc18ccc69a0f0f9cb9e17be6c196 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Mon, 12 Aug 2013 09:28:15 +0200 Subject: Update to MediaWiki 1.21.1 --- includes/SquidPurgeClient.php | 47 +++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'includes/SquidPurgeClient.php') diff --git a/includes/SquidPurgeClient.php b/includes/SquidPurgeClient.php index 8eb0f6bf..f5fd1950 100644 --- a/includes/SquidPurgeClient.php +++ b/includes/SquidPurgeClient.php @@ -21,9 +21,9 @@ */ /** - * An HTTP 1.0 client built for the purposes of purging Squid and Varnish. - * Uses asynchronous I/O, allowing purges to be done in a highly parallel - * manner. + * An HTTP 1.0 client built for the purposes of purging Squid and Varnish. + * Uses asynchronous I/O, allowing purges to be done in a highly parallel + * manner. * * Could be replaced by curl_multi_exec() or some such. */ @@ -123,7 +123,7 @@ class SquidPurgeClient { return array( $socket ); } - /** + /** * Get the host's IP address. * Does not support IPv6 at present due to the lack of a convenient interface in PHP. */ @@ -176,11 +176,32 @@ class SquidPurgeClient { * @param $url string */ public function queuePurge( $url ) { + global $wgSquidPurgeUseHostHeader; $url = SquidUpdate::expand( str_replace( "\n", '', $url ) ); - $this->requests[] = "PURGE $url HTTP/1.0\r\n" . - "Connection: Keep-Alive\r\n" . - "Proxy-Connection: Keep-Alive\r\n" . - "User-Agent: " . Http::userAgent() . ' ' . __CLASS__ . "\r\n\r\n"; + $request = array(); + if ( $wgSquidPurgeUseHostHeader ) { + $url = wfParseUrl( $url ); + $host = $url['host']; + if ( isset( $url['port'] ) && strlen( $url['port'] ) > 0 ) { + $host .= ":" . $url['port']; + } + $path = $url['path']; + if ( isset( $url['query'] ) && is_string( $url['query'] ) ) { + $path = wfAppendQuery( $path, $url['query'] ); + } + $request[] = "PURGE $path HTTP/1.1"; + $request[] = "Host: $host"; + } else { + $request[] = "PURGE $url HTTP/1.0"; + } + $request[] = "Connection: Keep-Alive"; + $request[] = "Proxy-Connection: Keep-Alive"; + $request[] = "User-Agent: " . Http::userAgent() . ' ' . __CLASS__; + // Two ''s to create \r\n\r\n + $request[] = ''; + $request[] = ''; + + $this->requests[] = implode( "\r\n", $request ); if ( $this->currentRequestIndex === null ) { $this->nextRequest(); } @@ -272,7 +293,7 @@ class SquidPurgeClient { if ( count( $lines ) < 2 ) { return 'done'; } - if ( $this->readState == 'status' ) { + if ( $this->readState == 'status' ) { $this->processStatusLine( $lines[0] ); } else { // header $this->processHeaderLine( $lines[0] ); @@ -297,7 +318,7 @@ class SquidPurgeClient { return 'done'; } default: - throw new MWException( __METHOD__.': unexpected state' ); + throw new MWException( __METHOD__ . ': unexpected state' ); } } @@ -352,7 +373,7 @@ class SquidPurgeClient { * @param $msg string */ protected function log( $msg ) { - wfDebugLog( 'squid', __CLASS__." ($this->host): $msg\n" ); + wfDebugLog( 'squid', __CLASS__ . " ($this->host): $msg\n" ); } } @@ -408,14 +429,14 @@ class SquidPurgeClientPool { $numReady = socket_select( $readSockets, $writeSockets, $exceptSockets, $timeout ); wfRestoreWarnings(); if ( $numReady === false ) { - wfDebugLog( 'squid', __METHOD__.': Error in stream_select: ' . + wfDebugLog( 'squid', __METHOD__ . ': Error in stream_select: ' . socket_strerror( socket_last_error() ) . "\n" ); break; } // Check for timeout, use 1% tolerance since we aimed at having socket_select() // exit at precisely the overall timeout if ( microtime( true ) - $startTime > $this->timeout * 0.99 ) { - wfDebugLog( 'squid', __CLASS__.": timeout ({$this->timeout}s)\n" ); + wfDebugLog( 'squid', __CLASS__ . ": timeout ({$this->timeout}s)\n" ); break; } elseif ( !$numReady ) { continue; -- cgit v1.2.3-54-g00ecf