module Merb # All of your controllers will inherit from Merb::Controller. This # superclass takes care of parsing the incoming headers and body into # params and cookies and headers. If the request is a file upload it will # stream it into a tempfile and pass in the filename and tempfile object # to your controller via params. It also parses the ?query=string and # puts that into params as well. class Controller attr_accessor :status # parses the http request into params, headers and cookies # that you can use in your controller classes. Also handles # file uploads by writing a tempfile and passing a reference # in params. def initialize(req, env, args, method=(env['REQUEST_METHOD']||"GET")) #:nodoc: env = MerbHash[env.to_hash] puts env.inspect if $DEBUG puts req.inspect if $DEBUG @layout = 'application' @status, @method, @env, @headers, @root = 200, method.downcase, env, {'Content-Type'=>'text/html'}, env['SCRIPT_NAME'].sub(/\/$/,'') @k = query_parse(env['HTTP_COOKIE'], ';,') qs = query_parse(env['QUERY_STRING']) @in = req if %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)|n.match(env['CONTENT_TYPE']) b = /(?:\r?\n|\A)#{Regexp::quote("--#$1")}(?:--)?\r$/ until @in.eof? fh=MerbHash[] for l in @in case l when "\r\n" : break when /^Content-Disposition: form-data;/ fh.update MerbHash[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten] when /^Content-Type: (.+?)(\r$|\Z)/m puts "=> fh[type] = #$1" fh[:type] = $1 end end fn=fh[:name] o=if fh[:filename] o=fh[:tempfile]=Tempfile.new(:Merb) o.binmode else fh="" end while l=@in.read(16384) if l=~b o<<$`.chomp @in.seek(-$'.size,IO::SEEK_CUR) break end o< 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 # accessor for @params. Please use params and # never @params directly. def params @params end # accessor for @cookies. Please use cookies and # never @cookies directly. def cookies @cookies end # accessor for @headers. Please use headers and # never @headers directly. def headers @headers 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.update(n,&m)rescue([*o]<

No Matching Route

" end def to_s @status = 404 "

No Matching Route s

" end end