Skip to content

Commit 721e43a

Browse files
author
James Addison
committed
Fixing PURGE calls: Host names on a non-standard port would cause Varnish to not be able to find the cached object (common scenario in a development environment). Also, '?' would always be appended to the URL even if there was no query string, causing a PURGE miss.
1 parent 203b9d5 commit 721e43a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

varnish.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def http_purge_url(url):
5151
"""
5252
url = urlparse(url)
5353
connection = HTTPConnection(url.hostname, url.port or 80)
54-
connection.request('PURGE', '%s?%s' % (url.path or '/', url.query), '',
55-
{'Host': url.hostname})
54+
path = url.path or '/'
55+
connection.request('PURGE', '%s?%s' % (path, url.query) if url.query else path, '',
56+
{'Host': '%s:%s' % (url.hostname, url.port) if url.port else url.hostname})
5657
response = connection.getresponse()
5758
if response.status != 200:
5859
logging.error('Purge failed with status: %s' % response.status)

0 commit comments

Comments
 (0)