Guest User

Untitled

a guest
Feb 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. def initialize(req, env, method=(env['REQUEST_METHOD']||"GET")) #:nodoc:
  2. env = Hash[env.to_hash]
  3. puts env.inspect
  4. @status, @method, @env, @headers, @root = 200, method.downcase, env,
  5. {'Content-Type'=>'text/html'}, env['SCRIPT_NAME'].sub(/\/$/,'')
  6. @k = query_parse(env['HTTP_COOKIE'], ';,')
  7. qs = query_parse(env['QUERY_STRING'])
  8. @in = req
  9. if %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)|n.match(env['CONTENT_TYPE'])
  10. b = /(?:\r?\n|\A)#{Regexp::quote("--#$1")}(?:--)?\r$/
  11. until @in.eof?
  12. fh=Hash[]
  13. for l in @in
  14. case l
  15. when "\r\n" : break
  16. when /^Content-Disposition: form-data;/
  17. fh.update Hash[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten]
  18. when /^Content-Type: (.+?)(\r$|\Z)/m
  19. puts "=> fh[type] = #$1"
  20. fh[:type] = $1
  21. end
  22. end
  23. fn=fh[:name]
  24. o=if fh[:filename]
  25. o=fh[:tempfile]=Tempfile.new(:Merb)
  26. o.binmode
  27. else
  28. fh=""
  29. end
  30. while l=@in.read(16384)
  31. if l=~b
  32. o<<$`.chomp
  33. @in.seek(-$'.size,IO::SEEK_CUR)
  34. break
  35. end
  36. o<<l
  37. end
  38. qs[fn]=fh if fn
  39. fh[:tempfile].rewind if fh.is_a?Hash
  40. end
  41. elsif @method == "post"
  42. qs.merge!(query_parse(@in.read))
  43. end
  44. @cookies, @params = @k.dup, qs.dup
  45. end
Add Comment
Please, Sign In to add comment