Class: Goliath::Rack::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/goliath/rack/params.rb

Overview

A middle ware to parse params. This will parse both the query string parameters and the body and place them into the params hash of the Goliath::Env for the request.

Examples:

use Goliath::Rack::Params

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Params

Returns a new instance of Params.



13
14
15
# File 'lib/goliath/rack/params.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
# File 'lib/goliath/rack/params.rb', line 17

def call(env)
  env['params'] = retrieve_params(env)
  @app.call(env)
end

#retrieve_params(env) ⇒ Object



22
23
24
25
26
27
# File 'lib/goliath/rack/params.rb', line 22

def retrieve_params(env)
  params = {}
  params.merge!(::Rack::Utils.parse_query(env['QUERY_STRING']))
  params.merge!(::Rack::Utils.parse_query(env['rack.input'].read)) unless env['rack.input'].nil?
  params
end