Sha256: 5f1910bdd4f875572270a6ac7a03153bff6347509662ba8778c74a0b464b954c

Contents?: true

Size: 649 Bytes

Versions: 10

Compression:

Stored size: 649 Bytes

Contents

module Rasti
  module Web
    class Request < Rack::Request

      def params
        @params ||= Hash::Indifferent.new.tap do |hash|
          hash.update self.GET
          hash.update self.POST
          hash.update env[ROUTE_PARAMS] if env.key? ROUTE_PARAMS
          hash.update JSON.parse(body_text) if json? && body_text
        end
      end

      def body_text
        @body_text ||= begin 
          text = body.read
          body.rewind
          text
        end
      end

      def json?
        content_type && ContentType.parse(content_type).mime_type == 'application/json' 
      rescue 
        false
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rasti-web-2.0.0 lib/rasti/web/request.rb
rasti-web-1.2.1 lib/rasti/web/request.rb
rasti-web-1.2.0 lib/rasti/web/request.rb
rasti-web-1.1.0 lib/rasti/web/request.rb
rasti-web-1.0.0 lib/rasti/web/request.rb
rasti-web-0.2.3 lib/rasti/web/request.rb
rasti-web-0.2.2 lib/rasti/web/request.rb
rasti-web-0.2.1 lib/rasti/web/request.rb
rasti-web-0.2.0 lib/rasti/web/request.rb
rasti-web-0.1.1 lib/rasti/web/request.rb