Skip to content

Commit e9f97d7

Browse files
committed
Add optional headers to purge call (fix #117)
1 parent 060ca17 commit e9f97d7

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

doc/proxy-clients.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ path::
103103
->flush()
104104
;
105105

106+
You can specify HTTP headers as the second argument to ``purge()``.
107+
For instance:
108+
109+
$client
110+
->purge('/some/path', array('X-Foo' => 'bar')
111+
->flush()
112+
;
113+
114+
Please note that purge will invalidate all variants, so you do not have to
115+
send any headers that you vary on, such as ``Accept``.
116+
106117
Refresh
107118
~~~~~~~
108119

src/ProxyClient/Invalidation/PurgeInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ interface PurgeInterface extends ProxyClientInterface
3030
* If the $url is just a path, the proxy client class will add a default
3131
* host name.
3232
*
33-
* @param string $url Path or URL to purge.
33+
* @param string $url Path or URL to purge.
34+
* @param array $headers Extra HTTP headers to send to the caching proxy
35+
* (optional)
3436
*
3537
* @return $this
3638
*/
37-
public function purge($url);
39+
public function purge($url, array $headers = array());
3840
}

src/ProxyClient/Nginx.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public function refresh($url, array $headers = array())
7474
/**
7575
* {@inheritdoc}
7676
*/
77-
public function purge($url)
77+
public function purge($url, array $headers = array())
7878
{
7979
$purgeUrl = $this->purgeLocation.$url;
80-
$this->queueRequest(self::HTTP_METHOD_PURGE, $purgeUrl);
80+
$this->queueRequest(self::HTTP_METHOD_PURGE, $purgeUrl, $headers);
8181

8282
return $this;
8383
}

src/ProxyClient/Varnish.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public function banPath($path, $contentType = null, $hosts = null)
109109
/**
110110
* {@inheritdoc}
111111
*/
112-
public function purge($url)
112+
public function purge($url, array $headers = array())
113113
{
114-
$this->queueRequest(self::HTTP_METHOD_PURGE, $url);
114+
$this->queueRequest(self::HTTP_METHOD_PURGE, $url, $headers);
115115

116116
return $this;
117117
}

tests/Unit/ProxyClient/VarnishTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ function ($requests) use ($self) {
120120
$self->assertEquals('127.0.0.1', $requests[2]->getHost());
121121
$self->assertEquals('8080', $requests[2]->getPort());
122122
$self->assertEquals('/url/two', $requests[2]->getPath());
123+
$self->assertEquals('bar', $requests[2]->getHeader('X-Foo'));
123124

124125
$self->assertEquals('123.123.123.2', $requests[3]->getHost());
125126
$self->assertEquals('/url/two', $requests[3]->getPath());
127+
$self->assertEquals('bar', $requests[3]->getHeader('X-Foo'));
126128

127129
return true;
128130
}
@@ -138,7 +140,7 @@ function ($requests) use ($self) {
138140
$varnish = new Varnish($ips, 'my_hostname.dev', $client);
139141

140142
$varnish->purge('/url/one');
141-
$varnish->purge('/url/two');
143+
$varnish->purge('/url/two', array('X-Foo' => 'bar'));
142144

143145
$varnish->flush();
144146
}

0 commit comments

Comments
 (0)