Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def initialize(req, env, method=(env['REQUEST_METHOD']||"GET")) #:nodoc:
- env = Hash[env.to_hash]
- puts env.inspect
- @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=Hash[]
- for l in @in
- case l
- when "\r\n" : break
- when /^Content-Disposition: form-data;/
- fh.update Hash[*$'.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<<l
- end
- qs[fn]=fh if fn
- fh[:tempfile].rewind if fh.is_a?Hash
- end
- elsif @method == "post"
- qs.merge!(query_parse(@in.read))
- end
- @cookies, @params = @k.dup, qs.dup
- end
Add Comment
Please, Sign In to add comment