Skip to content

Instantly share code, notes, and snippets.

@dasch
Created September 1, 2011 09:17
Show Gist options
  • Select an option

  • Save dasch/1185778 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

looks like java-servlets to me ;-)

@dasch

dasch commented Sep 27, 2011

Copy link
Copy Markdown
Author

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

dasch commented Sep 27, 2011 via email

Copy link
Copy Markdown
Author

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