jcelliott/turnpike — pull request #27 by maxpersson (2013-10-09 15:13:42+00:00)
Title: Add server pub/sub handlers

This implements two handlers that can be set on the server; one that is called when a client subscribes to a topic and one that is called on publishes to a topic. The URI that is used to register both cases can be a partial URI ("http://api.example.com/event") or a full URI ("http://api.example.com/event#test") in which case the most descriptive URI is called. This way general catch-all handlers can be added and also more specific handlers to certain topics.

In the subscription handler a client can be allowed or denied to subscribe by returning true or false, this will come in handy when implementing the CRA authentication where permissions control which topics can be subscribed by which client.

The publish handler can be used to modify the event by returning a new version, or cancel it altogether by returning nil.

I added basic tests, but more testing on the partial URL matching needs to be done.