Class: Jpmobile::ParamsFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/jpmobile/rack/params_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ParamsFilter

Returns a new instance of ParamsFilter


5
6
7
# File 'lib/jpmobile/rack/params_filter.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jpmobile/rack/params_filter.rb', line 9

def call(env)
  # 入力
  if @mobile = env['rack.jpmobile'] and @mobile.apply_params_filter?
    # パラメータをkey, valueに分解
    # form_params
    unless env['REQUEST_METHOD'] == 'GET' || env['REQUEST_METHOD'] == 'HEAD'
      unless env['CONTENT_TYPE'] =~ /application\/json|application\/xml/
        env['rack.input'] = StringIO.new(parse_query(env['rack.input'].read))
      end
    end

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

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

  [status, env, body]
end