I spent some time early this week trying to debug why some test was failing. It was using RESTeasy and I wanted to find out exactly what HTTP packets it was sending. If I was on a windows machine, I’d look towards Fiddler, but I couldn’t find anything easy on mac, so I wrote a little ruby script that I could point the client at and dump out all headers and request body.
It looks like this:
require 'webrick' include WEBrick class Simple < WEBrick::HTTPServlet::AbstractServlet def do_POST(request, response) puts "Body: " + request.body puts "Header: " + request.raw_header.to_s response.status = 200 end end server = HTTPServer.new(:Port => 5899) server.mount "/", Simple ['TERM', 'INT'].each do |signal| trap(signal){ server.shutdown } end server.start
Update
Upon publishing this, I got a couple of alternatives worth looking into for next time.
- Jim suggested using tcptrace; and
- Gaz suggested using the following command
sudo tcpdump -vvv -A -s 0 -i en1 tcp ‘port 5899’
This is just yet another example about why it’s important to have diversity when problem solving. I didn’t even know about these tools. Now I do and you do too.