(bug 39005) Add $wgPurgeHttp11.
authorDaniel Friesen <pub-github@nadir-seen-fire.com>
Sun, 1 Apr 2012 22:34:35 +0000 (15:34 -0700)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 15 Oct 2012 00:57:51 +0000 (00:57 +0000)
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
includes/DefaultSettings.php
includes/SquidPurgeClient.php

index ade0b68..b9fc458 100644 (file)
@@ -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.
index 0f02efc..598c346 100644 (file)
@@ -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
index 4aecf2e..cb33ead 100644 (file)
@@ -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();
                }