Skip to content

Instantly share code, notes, and snippets.

@dasch
Created September 1, 2011 09:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasch/1185778 to your computer and use it in GitHub Desktop.
Save dasch/1185778 to your computer and use it in GitHub Desktop.
Re-thought Rack API
class Middleware
# Processes a request before it reaches the application.
#
# The middleware can change the flow of the request/response chain by:
# - Raising an exception, which will halt the process
# - Returning an instance of Response, which will go through the middleware layer
#
# Returning any other value will not do anything.
def process_request(request)
# ...
end
def process_response(request, response)
# ...
end
def process_exception(request, exception)
# ...
end
end
@mkristian
Copy link

looks like java-servlets to me ;-)

@dasch
Copy link
Author

dasch commented Sep 27, 2011

Perhaps :-)

It would allow non-recursive middleware processing, e.g.

middlewares.each {|middleware| middleware.process_request(request) }
response = application.call(request)
middlewares.reverse.each {|middleware| middleware.process_response(request, response) }

This is overly simplified, but should alleviate some of the GC issues caused by Rack.

@dasch
Copy link
Author

dasch commented Sep 27, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment