Sha256: 60531ec6a996d9585f0f3c36188464b67505d426bdf65e416d046334a8d9c994

Contents?: true

Size: 718 Bytes

Versions: 50

Compression:

Stored size: 718 Bytes

Contents

require 'stringio'
require 'rack/request'
class Rack::App::Payload::Parser
  require 'rack/app/payload/parser/builder'

  DEFAULT_PARSER = proc { |io| io.read }

  def initialize(content_type__parsers = {})
    raise unless content_type__parsers.is_a?(Hash)
    @content_type__parsers = content_type__parsers
  end

  def parse_io(content_type, io)
    parser_for(content_type.to_s).call(io)
  end

  def parse_env(env)
    request = Rack::Request.new(env)
    parse_io(request.content_type, request.body)
  end

  def parse_string(content_type, str)
    parse_io(content_type, StringIO.new(str))
  end

  protected

  def parser_for(content_type)
    @content_type__parsers[content_type] || DEFAULT_PARSER
  end

end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
rack-app-6.1.0 lib/rack/app/payload/parser.rb
rack-app-6.0.0 lib/rack/app/payload/parser.rb
rack-app-5.12.0 lib/rack/app/payload/parser.rb
rack-app-5.11.1 lib/rack/app/payload/parser.rb
rack-app-5.11.0 lib/rack/app/payload/parser.rb
rack-app-5.10.2 lib/rack/app/payload/parser.rb
rack-app-5.10.1 lib/rack/app/payload/parser.rb
rack-app-5.10.0 lib/rack/app/payload/parser.rb
rack-app-5.9.0 lib/rack/app/payload/parser.rb
rack-app-5.8.0 lib/rack/app/payload/parser.rb