module Merb class Controller attr_accessor :status, :headers # 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<