diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-28 15:14:37 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-28 15:14:37 -0700 |
commit | af7980d379cc3357e08a5bd4c6b0a4b9cf373664 (patch) | |
tree | 32ef91b18a1e4366ff23405dfa387b2cfcfc81b3 | |
parent | 360d374ab1a263fcf81a18d6e5ac74cccccbc7e9 (diff) | |
download | rack-af7980d379cc3357e08a5bd4c6b0a4b9cf373664.tar.gz |
use parse states in the mime part methods
-rw-r--r-- | lib/rack/multipart/parser.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/rack/multipart/parser.rb b/lib/rack/multipart/parser.rb index a357a857..c574474d 100644 --- a/lib/rack/multipart/parser.rb +++ b/lib/rack/multipart/parser.rb @@ -168,10 +168,11 @@ module Rack filename = content_type = name = nil - until head && @buf =~ rx - if !head && i = @buf.index(EOL+EOL) + state = :HEAD + loop do # read until we have a header and separator in the buffer + if state == :HEAD && @buf.index(EOL + EOL) + i = @buf.index(EOL+EOL) head = @buf.slice!(0, i+2) # First \r\n - @buf.slice!(0, 2) # Second \r\n content_type = head[MULTIPART_CONTENT_TYPE, 1] @@ -188,21 +189,18 @@ module Rack file = body body.binmode if body.respond_to?(:binmode) end - - next + state = :BODY end - # Save the read body part. - if head && (@boundary_size+4 < @buf.size) - body << @buf.slice!(0, @buf.size - (@boundary_size+4)) - end + break if state == :BODY && @buf =~ rx content = @io.read(@bufsize) - handle_empty_content!(content) and break + handle_empty_content!(content) @buf << content end + [head, filename, content_type, name, body, file] end |