[Zope-Checkins] SVN: Zope/trunk/ Collector #1657: preserve 'Host:' header when PURGEing the accelerator cache.

Tres Seaver tseaver at zope.com
Tue Jan 11 12:59:36 EST 2005


Log message for revision 28780:
  Collector #1657:  preserve 'Host:' header when PURGEing the accelerator cache.
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
  A   Zope/trunk/lib/python/Products/StandardCacheManagers/tests/
  A   Zope/trunk/lib/python/Products/StandardCacheManagers/tests/__init__.py
  A   Zope/trunk/lib/python/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2005-01-11 17:24:49 UTC (rev 28779)
+++ Zope/trunk/doc/CHANGES.txt	2005-01-11 17:59:36 UTC (rev 28780)
@@ -51,6 +51,9 @@
 
     Bugs fixed
 
+      - Collector #1657:  Don't break host-based virtual hosting when
+        purging an HTTP accelerator.
+
       - DTML Methods were not interoperable with the new filestream_iterator
         and caches based on it (FileCacheManager).
 

Modified: Zope/trunk/lib/python/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
===================================================================
--- Zope/trunk/lib/python/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py	2005-01-11 17:24:49 UTC (rev 28779)
+++ Zope/trunk/lib/python/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py	2005-01-11 17:59:36 UTC (rev 28780)
@@ -62,12 +62,10 @@
                 p = path[:-1] + ob_path
             else:
                 p = path + ob_path
-            h = httplib.HTTP(host)
-            h.putrequest('PURGE', p)
-            h.endheaders()
-            errcode, errmsg, headers = h.getreply()
-            h.getfile().read()  # Mandatory for httplib?
-            results.append('%s %s' % (errcode, errmsg))
+            h = httplib.HTTPConnection(host)
+            h.request('PURGE', p)
+            r = h.getresponse()
+            results.append('%s %s' % (r.status, r.reason))
         return 'Server response(s): ' + ';'.join(results)
 
     def ZCache_get(self, ob, view_name, keywords, mtime_func, default):

Added: Zope/trunk/lib/python/Products/StandardCacheManagers/tests/__init__.py
===================================================================
--- Zope/trunk/lib/python/Products/StandardCacheManagers/tests/__init__.py	2005-01-11 17:24:49 UTC (rev 28779)
+++ Zope/trunk/lib/python/Products/StandardCacheManagers/tests/__init__.py	2005-01-11 17:59:36 UTC (rev 28780)
@@ -0,0 +1,17 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Unit tests for StandardCacheManagers product.
+
+$Id$
+"""

Added: Zope/trunk/lib/python/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py
===================================================================
--- Zope/trunk/lib/python/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py	2005-01-11 17:24:49 UTC (rev 28779)
+++ Zope/trunk/lib/python/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py	2005-01-11 17:59:36 UTC (rev 28780)
@@ -0,0 +1,99 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Unit tests for AcceleratedCacheManager module.
+
+$Id$
+"""
+import unittest
+import threading
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+from BaseHTTPServer import HTTPServer
+
+class PurgingHTTPRequestHandler(SimpleHTTPRequestHandler):
+
+    protocol_version = 'HTTP/1.0'
+
+    def do_PURGE(self):
+
+        """Serve a PURGE request."""
+        self.server.test_case.purged_host = self.headers.get('Host','xxx')
+        self.server.test_case.purged_path = self.path
+        self.send_response(200)
+        self.end_headers()
+
+    def log_request(self, code='ignored', size='ignored'):
+        pass
+
+
+class DummyObject:
+
+    _PATH = '/path/to/object'
+
+    def getPhysicalPath(self):
+        return tuple(self._PATH.split('/'))
+
+class AcceleratedHTTPCacheTests(unittest.TestCase):
+
+    _SERVER_PORT = 1888
+    thread = purged_host = purged_path = None
+
+    def tearDown(self):
+        if self.thread:
+            self.httpd.server_close()
+            self.thread.join()
+
+    def _getTargetClass(self):
+
+        from Products.StandardCacheManagers.AcceleratedHTTPCacheManager \
+            import AcceleratedHTTPCache
+
+        return AcceleratedHTTPCache
+
+    def _makeOne(self, *args, **kw):
+
+        return self._getTargetClass()(*args, **kw)
+
+    def _handleServerRequest(self):
+
+        server_address = ('', self._SERVER_PORT)
+
+        self.httpd = HTTPServer(server_address, PurgingHTTPRequestHandler)
+        self.httpd.test_case = self
+
+        sa = self.httpd.socket.getsockname()
+        self.thread = threading.Thread(target=self.httpd.handle_request)
+        self.thread.start()
+
+    def test_PURGE_passes_Host_header(self):
+
+        _TO_NOTIFY = 'localhost:%d' % self._SERVER_PORT
+
+        cache = self._makeOne()
+        cache.notify_urls = ['http://%s' % _TO_NOTIFY]
+        object = DummyObject()
+
+        # Run the HTTP server for this test.
+        self._handleServerRequest()
+
+        cache.ZCache_invalidate(object)
+
+        self.assertEqual(self.purged_host, _TO_NOTIFY)
+        self.assertEqual(self.purged_path, DummyObject._PATH)
+
+def test_suite():
+    return unittest.makeSuite(AcceleratedHTTPCacheTests)
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+



More information about the Zope-Checkins mailing list