#
# Rack doesn't works well with ruby 1.9.2
# there's no :each method in String anymore
# 
class Rack::Response
  def each(&callback)
    if @body.is_a? String
      @body.each_char(&callback)
    else
      @body.each(&callback)
    end
    @writer = callback
    @block.call(self)  if @block
  end
end

class Rack::Request
  alias_method :params_with_wrong_encoding, :params
  def params
    @params ||= encode_in_utf8(params_with_wrong_encoding)
  end

  protected
    def encode_in_utf8 hash
      r = {}
      hash.each do |k, v|
        r[k] = if v.is_a? String
          v.force_encoding("UTF-8")
        elsif v.is_a? Hash
          encode_in_utf8(v)
        else
          v
        end
      end
    end
end