Permalink
Browse files

Merge pull request #30 from JordiPolo/master

Printout contribution
  • Loading branch information...
2 parents f003cb0 + d5184f7 commit 9c1c02aafb3d21a7c1f3572acc1de77cfa539045 @rkh rkh committed Dec 10, 2012
Showing with 28 additions and 0 deletions.
  1. +1 −0 AUTHORS
  2. +1 −0 README.rdoc
  3. +1 −0 lib/rack/contrib.rb
  4. +25 −0 lib/rack/contrib/printout.rb
View
@@ -24,3 +24,4 @@ TJ Holowaychuk <tj@vision-media.ca>
anupom syam <anupom.syam@gmail.com>
ichverstehe <ichverstehe@gmail.com>
kubicek <jiri@kubicek.cz>
+Jordi Polo <mumismo@gmail.com>
View
@@ -48,6 +48,7 @@ interface:
* Rack::ResponseHeaders - Manipulates response headers object at runtime
* Rack::SimpleEndpoint - Creates simple endpoints with routing rules, similar to Sinatra actions
* Rack::TryStatic - Tries to match request to a static file
+* Rack::Printout - Prints the environment and the response per request
=== Use
View
@@ -38,4 +38,5 @@ def self.release
autoload :RelativeRedirect, "rack/contrib/relative_redirect"
autoload :StaticCache, "rack/contrib/static_cache"
autoload :TryStatic, "rack/contrib/try_static"
+ autoload :Printout, "rack/contrib/printout"
end
@@ -0,0 +1,25 @@
+module Rack
+ #prints the environment and request for simple debugging
+ class Printout
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ # See http://rack.rubyforge.org/doc/SPEC.html for details
+ puts "**********\n Environment\n **************"
+ puts env.inspect
+
+ puts "**********\n Response\n **************"
+ response = @app.call(env)
+ puts response.inspect
+
+ puts "**********\n Response contents\n **************"
+ response[2].each do |chunk|
+ puts chunk
+ end
+ puts "\n \n"
+ return response
+ end
+ end
+end

0 comments on commit 9c1c02a

Please sign in to comment.