Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #432 from spastorino/master

Make multipart parser not depend on having a Content-Length header
  • Loading branch information...
commit ccfdaf3ecac1870d7743db5a22302944868627c5 2 parents ea7ed1a + 6b23130
@rkh rkh authored
Showing with 13 additions and 4 deletions.
  1. +6 −4 lib/rack/multipart/parser.rb
  2. +7 −0 test/spec_multipart.rb
View
10 lib/rack/multipart/parser.rb
@@ -48,13 +48,15 @@ def setup_parse
@buf = ""
@params = Utils::KeySpaceConstrainedParams.new
- @content_length = @env['CONTENT_LENGTH'].to_i
@io = @env['rack.input']
@io.rewind
@boundary_size = Utils.bytesize(@boundary) + EOL.size
- @content_length -= @boundary_size
+ if @content_length = @env['CONTENT_LENGTH']
+ @content_length = @content_length.to_i
+ @content_length -= @boundary_size
+ end
true
end
@@ -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)
raise EOFError, "bad content body" if content.nil? || content.empty?
@buf << content
- @content_length -= content.size
+ @content_length -= content.size if @content_length
end
[head, filename, content_type, name, body]
View
7 test/spec_multipart.rb
@@ -360,4 +360,11 @@ def multipart_file(name)
params.should.equal({"description"=>"Very very blue"})
end
+ should "parse multipart upload with no content-length header" do
+ env = Rack::MockRequest.env_for '/', multipart_fixture(:webkit)
+ env['CONTENT_TYPE'] = "multipart/form-data; boundary=----WebKitFormBoundaryWLHCs9qmcJJoyjKR"
+ env.delete 'CONTENT_LENGTH'
+ params = Rack::Multipart.parse_multipart(env)
+ params['profile']['bio'].should.include 'hello'
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.