X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FSquidPurgeClient.php;h=f5fd1950851e1b3707eea051aca9541d7c0c83db;hb=bc9e97cd3f5af396b1901bd899bd82b2f8853d65;hp=4aecf2e5e76ad9de2023ef2dcabf33ed7c14fa7f;hpb=5fec9caec7d0a00772ad2056868cc3e1f1fc2d6e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SquidPurgeClient.php b/includes/SquidPurgeClient.php index 4aecf2e5e7..f5fd195085 100644 --- a/includes/SquidPurgeClient.php +++ b/includes/SquidPurgeClient.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;