ActionDispatch::Response has two modes:

   - A mode for building up a response that will then be passed to a Rack
   server. The only interface on this object is #each
   - A mode for taking a tuple of [status, headers, body] and making it
   available for inspection using the Response API.

The #body method is for the *second* mode, which is mostly used in testing
and debugging. The fact that #close calls the #body method is a mistake,
causing a (slow) debugging method to get called in the (fast) Rack response
mode.

We should probably be using a different method for the debugging version of
body, if Rack is calling #close on the result from #body (maybe something
like string_body). Alternatively, we may want to create a debugging response
object, and a to_something method to convert a response to that, but I worry
that it has untold potential for breakage.

Yehuda Katz
Architect | Strobe
(ph) 718.877.1325


On Tue, Nov 30, 2010 at 4:52 PM, John Firebaugh <[email protected]>wrote:

> On Tue, Nov 30, 2010 at 3:27 PM, Konstantin Haase <[email protected]> wrote:
> > Why not override #close in ActionDispatch::Response to avoid this issue?
>
> I agree that would fix this particular issue. My reluctance with that
> is that AD::Response#body would remain a dangerous method on its own,
> because it does not obey the semantics established by the base class.
> It's a Liskov Substitution Principle violation -- AD::Response cannot
> be safely substituted where Rack::Response is expected.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-core%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to