zedshaw/mongrel2 — pull request #134 by pjkundert (2012-05-25 18:48:32+00:00)
Title: Feature/forward: Request remembers raw 0MQ message for later forwarding

If a Python 0MQ handler wants to pass along an incoming Mongrel2 message to another handler, it cannot -- the origin incoming raw message from Mongrel2 has been discarded.

Arrange for m2py's Request object to remember the raw message, and add a forward(socket) method, to allow the message to be easily forwarded along to the specified socket.

This allows a Python handler to use m2py's handler.Connection in both the traditional way -- to receive Requests from Mongrel2, and to send responses back to Mongrel2, *or* -- to receive messages "forwarded" from some other Python handler, and then to send responses back to Mongrel2!

Very useful, if you want to write a broker to partially process Requests (say, for authentication), and then decide to forward them along to a set of sub-handlers for actually processing and generating the response to Mongrel2.

Request.parse(msg) -- returns a Request parsed from 'msg', which now also retains original msg
Request.forward(socket) -- forwards original msg to supplied 0MQ socket