5 Commits

Author SHA1 Message Date
Mislav Marohnić
f7e80bf4ce fix Builder::Handler comparison to another Handler 2011-05-13 10:24:56 -07:00
Mislav Marohnić
b47fb2922f cache middleware stack instead of rebuilding it on every request
The downside is, middleware can't be modified after making the first request:

  conn.use MyMiddleware       # => OK
  conn.get('/')
  conn.use AnotherMiddleware  # => raises a Builder::StackLocked error

On the plus side, the middleware stack is built only once and then cached as
the Connection#app object.

The Connection instance can always be "forked off" with the `dup` method and
modified as if it were fresh.
2011-05-08 14:20:51 -07:00
Mislav Marohnić
419ba4eaa4 optimize request/response cycle for parallel (asynchronous) mode
Changes:
 - there is no `env[:response]` during the request phase
 - middleware should attach `on_complete` handlers to the response object
   returned from `@app.call(env)` call
 - `on_complete` handlers execute immediately if the request is finished
 - Builder doesn't have the `run` method anymore
 - the default stack is now setup as soon as the Builder object has been initialized
 - the inner app for the stack is set when creating the request
2011-03-26 21:23:18 +01:00
Mislav Marohnić
d6d86dd043 extract multipart stuff from Adapter to Request::Multipart middleware 2011-03-26 21:20:21 +01:00
Mislav Marohnić
198546900c refactored builder so that middleware stack is more hackable
The problem with the old builder is that it was hard to see which middleware
is on the stack (it was stored in lambdas) and even harder to add new middleware
at arbitrary positions.

Incompatible changes:
 - `Builder.create` shouldn't be called without a block anymore
 - `Builder#run` doesn't push middleware to the stack anymore.
    Instead, it sets the inner app (overrides the default).
 - `Builder#handlers` are now stored in natural order
 - Handlers are no longer stored as lambdas. Instead, they are
   stored as lightweight `Handler` objects for easier inspection.
 - Inner app is no longer present among handlers.

Enhancements:
 - It's easy to see what's on the stack: `builder.handlers.inspect`
 - It's possible to edit the stack:
   - builder.insert_before(ExistingHandler, NewHandler)
   - builder.insert_after(...)
   - builder.swap(HandlerToReplace, NewHandler)
   - builder.delete(HandlerToDelete)
2011-03-26 21:16:42 +01:00