localshred/protobuf — pull request #137 by liveh2o (2014-01-29 23:28:42+00:00)
Title: Introduce the concept of a middleware stack (WIP)

In order to make PB more extensible, this introduces the concept of a middleware stack. It is invoked from the server and terminates at the dispatcher. The dispatcher returns an error or response proto which is then added to the response wrapper accordingly.

### WIP

This is a work in progress and as such doesn't have specs yet. I wanted to get a rough cut at how this will work and where it will hook into the hand-off from the server to the service dispatcher.

I tried to keep this as focused as possible, adding some notes for future enhancements as I saw them. The main problem I had was that the server module is dependent on instance variables that it sets and that are setup by other modules/classes. Ideally, we could move some of the request/response parsing code into the middleware stack, but the current architecture makes that difficult. I think there are a couple of things that could easily be moved into middleware (logging, stats), but I think another cut is necessary for that to happen.

### API

As far as I know, we're planning on extracting all of the servers into their own gems, so that may be an opportunity to further solidify the API making a clearer cut between what the server does and what the dispatcher does (and possibly even breaking up the dispatcher a bit).

// @abrandoned @localshred @devin-c