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

Ticket #8438 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[Patch] CgiRequest's body is not rewound after being read.

Reported by: s450r1 Assigned to: core
Priority: normal Milestone: 1.x
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc:

Description

I have been modifying Tobias Luetke's "Opinion 2" forum to run with rails trunk and noticed that the ToolsController#preview_textile action breaks on changeset [6764]. The problem is that request.raw_post returns an empty string because CgiRequest#body is a StringIO object that was read and not rewound. The attached patch rewind_request_body.diff includes a unit test illustrating the problem and code to rewind the body.

Here is the unit test that fails:

class CgiRequestNeedsRewoundTest < BaseCgiTest
  def test_body_should_be_rewound
    data = 'foo'
    fake_cgi = Struct.new(:env_table, :query_string, :stdinput).new(@request_hash, '', StringIO.new(data))
    fake_cgi.env_table['CONTENT_LENGTH'] = data.length
    fake_cgi.env_table['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
    request = ActionController::CgiRequest.new(fake_cgi)
    request.request_parameters
    assert_equal(0, request.body.pos)
  end
end
About your application's environment
Ruby version                 1.8.5 (i486-linux)
RubyGems version             0.9.2
Rails version                1.2.3
Active Record version        1.15.3
Action Pack version          1.13.3
Action Web Service version   1.2.3
Action Mailer version        1.3.3
Active Support version       1.4.2
Edge Rails revision          6813
Application root             /home/jad/src/opinion
Environment                  development
Database adapter             sqlite3
Database schema version      31

Also used mongrel 1.0.1 and firefox 2.0.0.2 for testing.

Attachments

rewind_request_body.diff (1.4 kB) - added by s450r1 on 05/23/07 04:02:42.

Change History

05/23/07 04:02:42 changed by s450r1

  • attachment rewind_request_body.diff added.

05/23/07 05:43:03 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [6815]) Rewind request body after reading it, if possible. Closes #8438.