Treating bodies as IO streams is only part of the problem. Today in Rack to stream responses, the rack app returns:
[-1, {}, []]
Which is interpreted by the app server like Thin, EventMachine as a deferrable response. The problem with this approach is that there's no way to process response headers asynchronously. Consider:
class Middleware
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
# This wouldn't work because rack returns [-1, {}, []] for an async response.
if headers['Content-Type'] == 'json'
Logger.info "Its JSON!"
end
status, headers, body
end
end
The logger line would never evaluate because of the `[-1, {}, []]` response.
The Goliath web server is the closest thing I've seen in Ruby land that considers these problems (https://github.com/postrank-labs/goliath/wiki/Middleware).
Does anybody know if there's a Rack 2.0 spec in the works that takes care of async request/response cycles?