module Merb module ControllerMixin # redirect to another url It can be like /foo/bar # for redirecting within your same app. Or it can # be a fully qualified url to another site. def redirect(url) MERB_LOGGER.info("Redirecting to: #{url}") @status = 302 headers.merge!({'Location'=> url}) return '' end # pass in a path to a file and this will set the # right headers and let mongrel do its thang and # serve the static file directly. def send_file(file) headers['X-SENDFILE'] = file return end # This uses nginx X-Accel-Redirect header to send # a file directly from nginx. See the nginx wiki: # http://wiki.codemongers.com/NginxXSendfile def nginx_send_file(file) headers['X-Accel-Redirect'] = file return end # parses a query string or the payload of a POST # request into the params hash. So for example: # /foo?bar=nik&post[title]=heya&post[body]=whatever # parses into: # {:bar => 'nik', :post => {:title => 'heya', :body => 'whatever}} def query_parse(qs, d = '&;') m = proc {|_,o,n|o.u(n,&m)rescue([*o]<