Read request body without deleting it

Viewed 373

So I have a MyHandler which has to know what's inside the request body:

class MyHandler
  include HTTP::Handler

  def call(context)
    p "MyHandler got body: " + context.request.body.not_nil!.gets_to_end
    call_next(context)
  end
end

server = HTTP::Server.new(42, [MyHandler.new]) do |context|
  p "Server got body: " + context.request.body.not_nil!.gets_to_end
end

As expected, after MyHandler has read, server receives a empty body. How can copy the body without modifying original context?

1 Answers
Related