|
43 | 43 | format = '%(asctime)s %(levelname)s %(message)s',
|
44 | 44 | )
|
45 | 45 |
|
| 46 | +def http_purge_url(url): |
| 47 | + """ |
| 48 | + Do an HTTP PURGE of the given asset. |
| 49 | + The URL is run through urlparse and must point to the varnish instance not the varnishadm |
| 50 | + """ |
| 51 | + url = urlparse(url) |
| 52 | + connection = HTTPConnection(url.hostname, url.port or 80) |
| 53 | + connection.request('PURGE', '%s?%s' % (url.path or '/', url.query), '', |
| 54 | + {'Host': url.hostname}) |
| 55 | + response = connection.getresponse() |
| 56 | + if response.status != 200: |
| 57 | + logging.error('Purge failed with status: %s' % response.status) |
| 58 | + return response |
| 59 | + |
46 | 60 | class VarnishHandler(Telnet):
|
47 | 61 | def __init__(self, host_port_timeout, secret=None, **kwargs):
|
48 | 62 | if isinstance(host_port_timeout, basestring):
|
@@ -240,6 +254,11 @@ def ban_list(self):
|
240 | 254 | """
|
241 | 255 | return self.fetch('ban.list')[1]
|
242 | 256 |
|
| 257 | + def purge_url(self, url): |
| 258 | + """ |
| 259 | + Wrapper for http_purge_url |
| 260 | + """ |
| 261 | + return http_purge_url(url) |
243 | 262 |
|
244 | 263 |
|
245 | 264 | class ThreadedRunner(Thread):
|
@@ -299,16 +318,4 @@ def close(self):
|
299 | 318 | self.run('close', threaded=True)
|
300 | 319 | self.servers = ()
|
301 | 320 |
|
302 |
| - def purge_url(self, url): |
303 |
| - """ |
304 |
| - Do an HTTP PURGE of the given asset. |
305 |
| - The URL is run through urlparse and must point to the varnish instance not the varnishadm |
306 |
| - """ |
307 |
| - url = urlparse(url) |
308 |
| - connection = HTTPConnection(url.hostname, url.port or 80) |
309 |
| - connection.request('PURGE', '%s?%s' % (url.path or '/', url.query), '', |
310 |
| - {'Host': url.hostname}) |
311 |
| - response = connection.getresponse() |
312 |
| - if response.status != 200: |
313 |
| - logging.error('Purge failed with status: %s' % response.status) |
314 |
| - return response |
| 321 | + |
0 commit comments