About bringing websocket support to Plone

At Plone Open Garden, a few week ago, I experimented on rebasing ZServer on top of Twisted reactor and its HTTP server (instead of asyncore and medusa). Not only did that bring Python 3 support for ZServer, but also option to benefit from the whole Twisted ecosystem.

One particularly interesting possible feature made possible by Twisted is Autobahn based websocket support to Plone.

The question is: What would you do with that?

At PLOG, I made a quick demo on how to use websocket with ZeroMQ to provide instant one to many notifications from zope.events trigged by one request to all subscribed clients.

My own first real use-case is mostly just that: to allow a service to subscribe changes from a Plone site using websocket (instead of my current solution of Plone calling a webhook of that service).

It's good to acknowledge that the websocket support I'm planning, would not magically make Plone asynchronous or faster. Briefly

  • websocket would work in parallel to HTTP (inside the same server) so that any path available for HTTP could also be connected with websocket (which is detected by connection upgrade-header)

  • each connection would have its path context and session cookie saved on its state

  • any call to Plone through websocket would create normal ZPublisher request to Plone (with the session cookie for authentication), although the request could carry a websocket only marker interface to match dedicated views; response body from request would be written to websocket

  • ZMQ pub-sub requires use of custom transaction data manager so that messages are published only at the second phase of successful commit

  • ZMQ pub-sub routing is based on a single bytestring, so making complex use cases secure require some creativity (and probably extra ZPublisher calls to ensure that each subscriber is still allowed to receive the latest message)

2 Likes