tags:

views:

43

answers:

1

I'm implementing a small HTTP server with Ruby using Mongrel. My code currently looks like this:

require 'mongrel.rb'

class SimpleHandler < Mongrel::HttpHandler
  def process(request, response)
    puts request.body # outputs #<StringIO:0xb7656e74> 
    response.start(200) do |head,out|
      head["Content-Type"] = "application/ocsp-responder"
      out.write("hello!\n")
    end
  end
end

h = Mongrel::HttpServer.new("127.0.0.1", "5000")
h.register("/", SimpleHandler.new)
h.run.join

As you can see in my sample, request.body does not output the POST data. How can I get it?

+1  A: 

StringIO#read should do it:

puts request.body.read
Romulo A. Ceccon
I was able to get the data using request.body.string, but your solution works as well. Thanks.
StackedCrooked