From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.229.225.21 with SMTP id iq21cs45289qcb; Tue, 30 Nov 2010 15:27:50 -0800 (PST) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncCJiRqd7pARDzkNbnBBoEgc3zyQ@googlegroups.com designates 10.223.102.131 as permitted sender) client-ip=10.223.102.131; Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncCJiRqd7pARDzkNbnBBoEgc3zyQ@googlegroups.com designates 10.223.102.131 as permitted sender) smtp.mail=rack-devel+bncCJiRqd7pARDzkNbnBBoEgc3zyQ@googlegroups.com; dkim=pass header.i=rack-devel+bncCJiRqd7pARDzkNbnBBoEgc3zyQ@googlegroups.com Received: from mr.google.com ([10.223.102.131]) by 10.223.102.131 with SMTP id g3mr572209fao.27.1291159669622 (num_hops = 1); Tue, 30 Nov 2010 15:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:received:received:mime-version :subject:from:in-reply-to:date:message-id:references:to:x-mailer :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type :content-transfer-encoding; bh=rcNCayRTCMvaShVyFEqFuvGZKk4DEobKG7SdLqKXXkY=; b=aYGsYVU9khjUfxUPhKdzG1tW2RQ1b4HZPMszZDnEqAMGiteem3/iNKQv0PSq9cvnlB sGcyhYrMHSxg8b7TO5SsuLdyPGH8tRfPzxDSnud/4VE+r8T0w+NnY9pWosnS5foiHKhy X99dVMcQeDXhSOy+HVhAzMu0lVESpE6ECRjBg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:mime-version:subject:from:in-reply-to:date :message-id:references:to:x-mailer:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type:content-transfer-encoding; b=Uy3lrsyf2CZm8UM+x1Q09Tqw9WZwyDG/onnhg6uAvqt9xnzvVddd1vq5ktpXYvh2I4 wboAXrhXynRQRv0rPW5PT8z1IhSyijDKsRl2vvq+XwdQtMa6dK1yM4oKB/SJlusS7XIg If+HkYtVMaemTPd5NPP4sGu5fy/1U4DROH9O8= Received: by 10.223.102.131 with SMTP id g3mr133049fao.27.1291159667475; Tue, 30 Nov 2010 15:27:47 -0800 (PST) X-BeenThere: rack-devel@googlegroups.com Received: by 10.204.81.69 with SMTP id w5ls3619029bkk.2.p; Tue, 30 Nov 2010 15:27:45 -0800 (PST) Received: by 10.204.154.197 with SMTP id p5mr919350bkw.12.1291159664963; Tue, 30 Nov 2010 15:27:44 -0800 (PST) Received: by 10.204.154.197 with SMTP id p5mr919349bkw.12.1291159664918; Tue, 30 Nov 2010 15:27:44 -0800 (PST) Received: from mail-fx0-f51.google.com (mail-fx0-f51.google.com [209.85.161.51]) by gmr-mx.google.com with ESMTP id j16si992054bkd.2.2010.11.30.15.27.44; Tue, 30 Nov 2010 15:27:44 -0800 (PST) Received-SPF: neutral (google.com: 209.85.161.51 is neither permitted nor denied by best guess record for domain of k.haase@finn.de) client-ip=209.85.161.51; Received: by mail-fx0-f51.google.com with SMTP id 15so4704687fxm.24 for ; Tue, 30 Nov 2010 15:27:44 -0800 (PST) Received: by 10.223.81.67 with SMTP id w3mr6677604fak.110.1291159662384; Tue, 30 Nov 2010 15:27:42 -0800 (PST) Received: from sd-16.stud.uni-potsdam.de (sd-16.stud.uni-potsdam.de [141.89.44.16]) by mx.google.com with ESMTPS id z1sm1864956fau.21.2010.11.30.15.27.39 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 30 Nov 2010 15:27:40 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1081) Subject: Re: Rack::Response#body vs ActionDispatch::Response#body From: Konstantin Haase In-Reply-To: Date: Wed, 1 Dec 2010 00:27:38 +0100 Message-Id: <77B5E57A-44A8-4911-B28F-FAF45062E0BF@finn.de> References: To: rack-devel@googlegroups.com X-Mailer: Apple Mail (2.1081) X-Original-Sender: k.haase@finn.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.161.51 is neither permitted nor denied by best guess record for domain of k.haase@finn.de) smtp.mail=k.haase@finn.de Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: Sender: rack-devel@googlegroups.com List-Subscribe: , List-Unsubscribe: , Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable I agree this is a Rails issue, accessing @body directly would be a step = backwards since being able to override #body is part of the API imo. Why not override #close in ActionDispatch::Response to avoid this issue? Konstantin On Nov 30, 2010, at 23:52 , John Firebaugh wrote: > The definitions of #body in Rack::Response and > ActionDispatch::Response are competing and causing performance > problems with streaming responses. Rack::Response provides > attr_accessor :body, while ActionDispatch::Response overrides that as > follows: >=20 > def body > str =3D '' > each { |part| str << part.to_s } > str > end >=20 > This is problematic in instances where a streaming body is used, due > to the definition of Rack::Response#close: >=20 > def close > body.close if body.respond_to?(:close) > end >=20 > Given these definitions, executing the Rack protocol on an > ActionDispatch::Response instance (calling '#each', then '#close') > causes the body to be enumerated twice -- once via the expected call > to #each, and a second time via the call chain #close -> #body -> > #each. See = https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4554 > for a user report of this problem. >=20 > This could be fixed by using the instance variable directly: >=20 > def close > @body.close if @body.respond_to?(:close) > end >=20 > However, I think ActionDispatch::Response's #body override is > dangerous and violates the principle of least surprise by removing the > symmetry between #body and #body=3D. IMHO, it would be better to = remove > the override. If the concatenating behavior is necessary, supply a > method named #body_text or a similar name that makes it clear that it > disables streaming. This option causes numerous Rails test failures, > however, as many tests are written to expect #body to return a string. >=20 > Thoughts?