notifyVirtualHostChanged(event)
Adjust cookie paths when IVirtualHostRequest information changes.
Given a event, this method should call a CookieClientIdManager's setRequestId if a cookie is present in the response for that manager. To demonstrate we create a dummy manager object and event:
>>> class DummyManager(object): ... implements(ICookieClientIdManager) ... namespace = 'foo' ... thirdparty = False ... request_id = None ... def setRequestId(self, request, id): ... self.request_id = id ... >>> manager = DummyManager() >>> component.provideUtility(manager, IClientIdManager) >>> from zope.publisher.http import HTTPRequest >>> class DummyEvent (object): ... request = HTTPRequest(StringIO(''), {}, None) >>> event = DummyEvent()
With no cookies present, the manager should not be called:
>>> notifyVirtualHostChanged(event) >>> manager.request_id is None True
However, when a cookie has been set, the manager is called so it can update the cookie if need be:
>>> event.request.response.setCookie('foo', 'bar') >>> notifyVirtualHostChanged(event) >>> manager.request_id 'bar'
If a server in front of Zope manages the ClientIds (Apache, Nginx), we don't need to take care about the cookies
>>> manager2 = DummyManager() >>> manager2.thirdparty = True >>> event2 = DummyEvent()
However, when a cookie has been set, the manager is called so it can update the cookie if need be:
>>> event2.request.response.setCookie('foo2', 'bar2') >>> notifyVirtualHostChanged(event2) >>> id = manager2.request_id >>> id is None True
Cleanup of the utility registration:
>>> import zope.component.testing >>> zope.component.testing.tearDown()