Created
August 15, 2011 21:35
-
-
Save damien/1147927 to your computer and use it in GitHub Desktop.
A simple rack middleware to debug the request pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage example | |
require "inspect_middleware" | |
use InspectMiddleware | |
run GenericSinatraApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InspectMiddleware | |
require "yaml" | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
puts | |
puts "-"*80 | |
puts "Request Pipeline" | |
print_middleware_class = lambda do |klass| | |
if middleware = klass.instance_variable_get(:@app) | |
print "#{middleware.class} -> " | |
print_middleware_class.call(middleware) | |
else | |
puts | |
puts "#{klass.class} is a rack endpoint" | |
puts | |
puts "Class:" | |
puts klass.inspect | |
puts "-"*80 | |
puts | |
end | |
end | |
print_middleware_class.call(@app) | |
@app.call(env) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------------------------------------------- | |
Request Pipeline | |
Rack::Static -> Rack::Sprockets::Base -> Rack::MobileDetect -> RedirectOnce -> Class -> | |
Class is a rack endpoint | |
Class: | |
Jelli::UI | |
-------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment