Sha256: 31b5e278e5f026ca9ae117c26602ab01b830394db8329104f0c17b1be878b939

Contents?: true

Size: 679 Bytes

Versions: 2

Compression:

Stored size: 679 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 = Hash.new(DEFAULT_PARSER)
    @content_type__parsers.merge!(content_type__parsers)
  end

  def parse_io(content_type, io)
    @content_type__parsers[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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-app-5.7.0 lib/rack/app/payload/parser.rb
rack-app-5.7.0.rc lib/rack/app/payload/parser.rb