Sha256: 55f923eb0134646c9493e3a9adb2e879c7d11952ceb4a9f16fb23370e907fec3

Contents?: true

Size: 1.1 KB

Versions: 24

Compression:

Stored size: 1.1 KB

Contents

# -*- coding: utf-8 -*-
# リクエストパラメータの変換
module Jpmobile
  module Rack
    class ParamsFilter
      def initialize(app)
        @app = app
      end

      def call(env)
        # 入力
        if @mobile = env['rack.jpmobile']
          # パラメータをkey, valueに分解
          # form_params
          if env['REQUEST_METHOD'] == 'POST'
            env['rack.input'] = StringIO.new(parse_query(env['rack.input'].read))
          end

          # query_params
          env['QUERY_STRING'] = parse_query(env['QUERY_STRING'])
        end

        status, env, body = @app.call(env)

        [status, env, body]
      end

      private
      def to_internal(str)
        ::Rack::Utils.escape(@mobile.to_internal(::Rack::Utils.unescape(str)))
      end
      def parse_query(str)
        return nil unless str

        new_array = []
        str.split("&").each do |param_pair|
          k, v = param_pair.split("=")
          k = to_internal(k) if k
          v = to_internal(v) if v
          new_array << "#{k}=#{v}" if k
        end

        new_array.join("&")
      end
    end
  end
end

Version data entries

24 entries across 19 versions & 1 rubygems

Version Path
jpmobile-1.0.0.pre.1 test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/params_filter.rb
jpmobile-1.0.0.pre test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/params_filter.rb
jpmobile-1.0.0.pre lib/jpmobile/rack/params_filter.rb
jpmobile-0.1.6 lib/jpmobile/rack/params_filter.rb