Sha256: 3b337ff471ef7f6e3e8191cab5b03fcfdf2a9d33082c17945f2d3c9bfc2ce6f9

Contents?: true

Size: 991 Bytes

Versions: 2

Compression:

Stored size: 991 Bytes

Contents

require 'active_support/core_ext/object/blank'

module Sparrow
  module Strategies
    class RawInput
      include Transformable

      attr_reader :env, :type

      def self.handle(env, type)
        self.new(env, type).handle
      end

      def initialize(env, type = :request, params = nil)
        @env    = env || {}
        @params = params
        @type   = type
      end

      def handle
        super
        handle_raw_rack
      end

      def params
        if @params
          @params
        else
          input_io = @env['rack.input']
          params   = input_io.send(:read)
          input_io.rewind
          params
        end
      end

      private

      def handle_raw_rack
        if params.present?
          new_raw_input      = json_body.force_encoding("BINARY")
          @env['rack.input'] = StringIO.new(new_raw_input)
          @env['rack.input'].rewind
          @env['CONTENT_LENGTH'] = new_raw_input.length
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cp-sparrow-0.0.12 lib/sparrow/strategies/raw_input.rb
cp-sparrow-0.0.11 lib/sparrow/strategies/raw_input.rb