Skip to content

Instantly share code, notes, and snippets.

@pablobm
Created August 19, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablobm/50c0ff22d536b991a84e1e1881cdf20c to your computer and use it in GitHub Desktop.
Save pablobm/50c0ff22d536b991a84e1e1881cdf20c to your computer and use it in GitHub Desktop.
Rack server that prints out any requests
# Run as follows:
#
# rackup -o 0.0.0.0 -O Threads=0:1
#
require 'json'
require 'pp'
run (Proc.new do |env|
req = Rack::Request.new(env)
puts "====================="
puts "#{req.request_method} #{req.path}"
unless req.GET.empty?
puts "--- query"
pp req.GET
end
if req.content_length.to_i > 0
puts "--- POST #{req.content_type}"
if req.content_type['json']
pp JSON.parse(req.body.read)
elsif req.POST?
pp req.POST
else
puts req.body.read
end
end
[
200,
{ 'Content-Type' => 'text/plain' },
[ '' ],
]
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment