From a8b3feec117865ddffc8429f2939fbd944240f16 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sun, 1 Apr 2012 15:34:35 -0700 Subject: [PATCH] (bug 39005) Add $wgPurgeHttp11. Allow SquidPurgeClient to send HTTP/1.1 PURGE requests with a Host header instead of only sending HTTP/1.0 requests with the whole url in the PURGE line. This is necessary to support some other reverse caching proxies like Varnish. Change-Id: I85fe93a8ca97c5169f250967540e29fc70725119 --- RELEASE-NOTES-1.21 | 3 +++ includes/DefaultSettings.php | 8 ++++++++ includes/SquidPurgeClient.php | 29 +++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index ade0b68585..b9fc4585cf 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -14,6 +14,9 @@ production. * (bug 29374) $wgVectorUseSimpleSearch is now enabled by default. * Deprecated $wgAllowRealName is removed. Use $wgHiddenPrefs[] = 'realname' instead. +* Added a $wgPurgeHttp11 setting to allow SquidPurgeClient to send PURGE requests + using HTTP/1.1 and a Host header instead of sending HTTP/1.0 requests with the + whole url inside the PURGE <...> HTTP/1.0 line. === New features in 1.21 === * (bug 34876) jquery.makeCollapsible has been improved in performance. diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0f02efc319..598c346d4d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2058,6 +2058,14 @@ $wgSquidServersNoPurge = array(); /** Maximum number of titles to purge in any one client operation */ $wgMaxSquidPurgeTitles = 400; +/** + * Whether to use HTTP/1.1 for squid purge requests + * false - Use HTTP/1.0 with a full url in the PURGE request. + * true - Use HTTP/1.1 with a Host header and PURGE path. + * @since 1.20 + */ +$wgPurgeHttp11 = false; + /** * Routing configuration for HTCP multicast purging. Add elements here to * enable HTCP and determine which purges are sent where. If set to an empty diff --git a/includes/SquidPurgeClient.php b/includes/SquidPurgeClient.php index 4aecf2e5e7..cb33ead943 100644 --- a/includes/SquidPurgeClient.php +++ b/includes/SquidPurgeClient.php @@ -176,11 +176,32 @@ class SquidPurgeClient { * @param $url string */ public function queuePurge( $url ) { + global $wgPurgeHttp11; $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 ( $wgPurgeHttp11 ) { + $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(); } -- 2.20.1