Class: Mongrel::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/squeeze_box.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.query_parse(qs, d = '&;') ⇒ Object

parses a query string or the payload of a POST request into the params hash. So for example: /foo?bar=nik&post=heya&post=whatever parses into: => ‘nik’, :post => {:title => ‘heya’, :body => ‘whatever’}



299
300
301
302
303
304
305
# File 'lib/squeeze_box.rb', line 299

def self.query_parse(qs, d = '&;')
  m = proc {|_,o,n|o.update(n,&m)rescue([*o]<<n)}
  (qs||'').split(/[#{d}] */n).inject(Hash[]) do |h,p| 
    k, v=unescape(p).split('=',2)
    h.update(k.split(/[\]\[]+/).reverse.inject(v) { |x,i| Hash[i,x] },&m)
  end
end

Instance Method Details

#cgi_paramsObject



312
313
314
315
316
317
318
# File 'lib/squeeze_box.rb', line 312

def cgi_params
  unless @_cgi_params
    @_cgi_params = HttpRequest.query_parse(@params[SqueezeBox::Const::QUERY_STRING] || '')
    @_cgi_params.update( HttpRequest.query_parse(body.read) ) if post?
  end
  @_cgi_params
end

#cookiesObject



320
321
322
# File 'lib/squeeze_box.rb', line 320

def cookies
  @_cookies ||= HttpRequest.query_parse(@params[SqueezeBox::Const::HTTP_COOKIE], ';,')
end

#get?Boolean

Returns:

  • (Boolean)


310
# File 'lib/squeeze_box.rb', line 310

def get?; params['REQUEST_METHOD'].upcase == 'GET'.upcase; end

#post?Boolean

^— by Ezra Zygmuntowicz; from merb/mixins/controller.rb

Returns:

  • (Boolean)


308
# File 'lib/squeeze_box.rb', line 308

def post?; params['REQUEST_METHOD'].upcase == 'POST'.upcase; end