Skip to content

Commit

Permalink
Merge pull request rack#1201 from janko-m/make-multipart-parsing-work…
Browse files Browse the repository at this point in the history
…-for-chunked-requests

Don't use #eof? when parsing multipart
  • Loading branch information
rafaelfranca authored and matthewd committed Dec 19, 2018
1 parent 8376dd1 commit cb1fdb6
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/rack/multipart/parser.rb
Expand Up @@ -39,8 +39,6 @@ def read(size)
str
end

def eof?; @content_length == @cursor; end

def rewind
@io.rewind
end
Expand All @@ -65,11 +63,11 @@ def self.parse(io, content_length, content_type, tmpfile, bufsize, qp)
io = BoundedIO.new(io, content_length) if content_length

parser = new(boundary, tmpfile, bufsize, qp)
parser.on_read io.read(bufsize), io.eof?
parser.on_read io.read(bufsize)

loop do
break if parser.state == :DONE
parser.on_read io.read(bufsize), io.eof?
parser.on_read io.read(bufsize)
end

io.rewind
Expand Down Expand Up @@ -181,8 +179,8 @@ def initialize(boundary, tempfile, bufsize, query_parser)
@collector = Collector.new tempfile
end

def on_read content, eof
handle_empty_content!(content, eof)
def on_read content
handle_empty_content!(content)
@buf << content
run_parser
end
Expand Down Expand Up @@ -358,10 +356,9 @@ def tag_multipart_encoding(filename, content_type, name, body)
end


def handle_empty_content!(content, eof)
def handle_empty_content!(content)
if content.nil? || content.empty?
raise EOFError if eof
return true
raise EOFError
end
end
end
Expand Down

0 comments on commit cb1fdb6

Please sign in to comment.