Sha256: ec52a97f6e2e8e013b05df226fda0acc990b31d2e6a14a9a266aed06c83f36c1

Contents?: true

Size: 652 Bytes

Versions: 2

Compression:

Stored size: 652 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.nil? && ContentType.parse(content_type).mime_type == 'application/json'
      rescue
        false
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rasti-web-2.1.1 lib/rasti/web/request.rb
rasti-web-2.1.0 lib/rasti/web/request.rb