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-11.0.2 lib/rack/app/payload/parser.rb
rack-app-11.0.1 lib/rack/app/payload/parser.rb
rack-app-11.0.0 lib/rack/app/payload/parser.rb
rack-app-10.0.0 lib/rack/app/payload/parser.rb
rack-app-9.0.0 lib/rack/app/payload/parser.rb
rack-app-8.1.0 lib/rack/app/payload/parser.rb
rack-app-8.0.1 lib/rack/app/payload/parser.rb
rack-app-8.0.0 lib/rack/app/payload/parser.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/payload/parser.rb
rack-app-7.7.0 lib/rack/app/payload/parser.rb
rack-app-7.6.5 lib/rack/app/payload/parser.rb
rack-app-7.6.4 lib/rack/app/payload/parser.rb
rack-app-7.6.3 lib/rack/app/payload/parser.rb
rack-app-7.6.2 lib/rack/app/payload/parser.rb
rack-app-7.6.1 lib/rack/app/payload/parser.rb
rack-app-7.6.0 lib/rack/app/payload/parser.rb
rack-app-7.5.2 lib/rack/app/payload/parser.rb
rack-app-7.5.1 lib/rack/app/payload/parser.rb
rack-app-7.5.0 lib/rack/app/payload/parser.rb
rack-app-7.4.0 lib/rack/app/payload/parser.rb