Created
August 19, 2016 10:07
-
-
Save pablobm/50c0ff22d536b991a84e1e1881cdf20c to your computer and use it in GitHub Desktop.
Rack server that prints out any requests
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
# 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