Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6815

Show
Ignore:
Timestamp:
05/23/07 05:43:00 (1 year ago)
Author:
bitsweat
Message:

Rewind request body after reading it, if possible. Closes #8438.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6806 r6815  
    11*SVN* 
     2 
     3* Rewind request body after reading it, if possible.  #8438 [s450r1] 
    24 
    35* Resource namespaces are inherited by their has_many subresources.  #8280 [marclove, ggarside] 
  • trunk/actionpack/lib/action_controller/request.rb

    r6786 r6815  
    331331        # Only multipart form parsing expects a stream. 
    332332        if strategy && strategy != :multipart_form 
    333           body = body.read(content_length) 
     333          data = body.read(content_length) 
     334          body.rewind if body.respond_to?(:rewind) 
     335          body = data 
    334336        end 
    335337 
  • trunk/actionpack/test/controller/cgi_test.rb

    r6786 r6815  
    6969  end 
    7070end 
     71 
     72 
     73class CgiRequestNeedsRewoundTest < BaseCgiTest 
     74  def test_body_should_be_rewound 
     75    data = 'foo' 
     76    fake_cgi = Struct.new(:env_table, :query_string, :stdinput).new(@request_hash, '', StringIO.new(data)) 
     77    fake_cgi.env_table['CONTENT_LENGTH'] = data.length 
     78    fake_cgi.env_table['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' 
     79 
     80    # Read the request body by parsing params. 
     81    request = ActionController::CgiRequest.new(fake_cgi) 
     82    request.request_parameters 
     83 
     84    # Should have rewound the body. 
     85    assert_equal 0, request.body.pos 
     86  end 
     87end