module Merb # controller class for the merb pocket-framework. 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 # Stolen from Camping without a twinge of remorse ;) def initialize(req, env, method=(env['REQUEST_METHOD']||"GET")) #:nodoc: env = MerbHash[env.to_hash] puts env.inspect if $DEBUG puts req.inspect if $DEBUG @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<