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-7.3.2 lib/rack/app/payload/parser.rb
rack-app-7.3.1 lib/rack/app/payload/parser.rb
rack-app-7.3.0 lib/rack/app/payload/parser.rb
rack-app-7.2.2 lib/rack/app/payload/parser.rb
rack-app-7.2.1 lib/rack/app/payload/parser.rb
rack-app-7.2.0 lib/rack/app/payload/parser.rb
rack-app-7.1.0 lib/rack/app/payload/parser.rb
rack-app-7.0.0 lib/rack/app/payload/parser.rb
rack-app-6.8.0 lib/rack/app/payload/parser.rb
rack-app-6.7.1 lib/rack/app/payload/parser.rb
rack-app-6.7.0 lib/rack/app/payload/parser.rb
rack-app-6.6.0 lib/rack/app/payload/parser.rb
rack-app-6.5.0 lib/rack/app/payload/parser.rb
rack-app-6.4.1 lib/rack/app/payload/parser.rb
rack-app-6.4.0 lib/rack/app/payload/parser.rb
rack-app-6.3.3 lib/rack/app/payload/parser.rb
rack-app-6.3.2 lib/rack/app/payload/parser.rb
rack-app-6.3.1 lib/rack/app/payload/parser.rb
rack-app-6.3.0 lib/rack/app/payload/parser.rb
rack-app-6.2.0 lib/rack/app/payload/parser.rb