Skip to content

Make multipart parser not depend on having a Content-Length header #432

Merged
merged 1 commit into from Sep 17, 2012

3 participants

@spastorino
Official Rack repositories member

Related ...

rails/rails#7556
and
#418

@rkh rkh merged commit ccfdaf3 into rack:master Sep 17, 2012

1 check passed

Details default The Travis build passed
@gioele gioele commented on the diff Sep 17, 2012
lib/rack/multipart/parser.rb
@io = @env['rack.input']
@io.rewind
@boundary_size = Utils.bytesize(@boundary) + EOL.size
- @content_length -= @boundary_size
+ if @content_length = @env['CONTENT_LENGTH']
@gioele
gioele added a note Sep 17, 2012

Couldn't you use

@content_length = @env['CONTENT_LENGTH']
@content_length = @content_length.to_i - @boundary_size unless @content_length.nil?

Using if together with assignment is very confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gioele gioele commented on the diff Sep 17, 2012
lib/rack/multipart/parser.rb
@@ -104,11 +106,11 @@ def get_current_head_and_filename_and_content_type_and_name_and_body
body << @buf.slice!(0, @buf.size - (@boundary_size+4))
end
- content = @io.read(BUFSIZE < @content_length ? BUFSIZE : @content_length)
+ content = @io.read(@content_length && BUFSIZE >= @content_length ? @content_length : BUFSIZE)
@gioele
gioele added a note Sep 17, 2012

The comparison is getting quite complex; could you simplify the code into

acceptable_length = @content_length && BUFSIZE >= @content_length 
content = @io.read(acceptable_length ? @content_length : BUFSIZE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.