Capture and print HTTP request

So I wanted to see what this app was exporting (http request wise), so I created the following Rack app to listen on a given port, then I could capture and print what the app was posting

Installed thin as the webserver

gem install thin

Write a simple rack app:

require 'rack'

module Rack
  class LogIt
    def initialize(app, options = {})
      @app = app
    end

    def call(env)
      r = Rack::Request.new(env)
      env.each_pair { |h,v| puts "#{h}: #{v}" }
      puts ''
      puts r.body.read
      @app.call env
    end
  end
end

app = Rack::Builder.new do
  use Rack::LogIt
  app = proc do |env|
    [ 200, {'Content-Type' => 'text/plain'}, ["Hello!"] ]
  end
  run app
end.to_app

server =  Thin::Server.new('0.0.0.0','3009', app, {})
server.start

Run like so:

thin -R app.rb start