From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.204.72.79 with SMTP id l15cs969542bkj; Mon, 17 Aug 2009 14:41:48 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.100.51.14 as permitted sender) client-ip=10.100.51.14; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.100.51.14 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.100.51.14]) by 10.100.51.14 with SMTP id y14mr8444067any.13.1250545307448 (num_hops = 1); Mon, 17 Aug 2009 14:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :mime-version:received:date:in-reply-to:x-ip:references:user-agent :x-http-useragent:message-id:subject:from:to:content-type :content-transfer-encoding:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; bh=IXrYNPlCEyeiKM8lXbys++0TA3R5nlYvX0IChNYQHXU=; b=IOBlpEelLBofN1eeAmhpSV9Ki5kQE2GdnPHq6jTgvPQpmC/Q9TF28xaJTWO1xRG0Ow GQhWQbKnOFTjUmhxc4ZceGddDxrUIPu2st99qKpngUZRl0zRrQSK8zCTlCaR+MAYIlHr GIG2p3OttvH9J2XbJE2pvKTxTQ5Tnv9ctBpfA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:mime-version:date:in-reply-to:x-ip :references:user-agent:x-http-useragent:message-id:subject:from:to :content-type:content-transfer-encoding:reply-to:sender:precedence :x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; b=ara1MsGmhZM+d4n+M5wiLKLMq0MOD8ybj70TXBlJUnWzLWJO1TmYMj1k1BeHhc8yuB O0MwsSLbSmhVDvwUak35jswR2mfrLCQ6R8RKlIu0R2yFV1L69kV1AgiGZJKcERRw+AZ6 PwgW3hFsRfl1bG/vd61ERJNVWe5ANkkKvquA0= Received: by 10.100.51.14 with SMTP id y14mr1287599any.13.1250545307352; Mon, 17 Aug 2009 14:41:47 -0700 (PDT) Received: by 10.176.46.2 with SMTP id t2gr1597yqt.0; Mon, 17 Aug 2009 14:41:43 -0700 (PDT) X-Sender: hongli@phusion.nl X-Apparently-To: rack-devel@googlegroups.com MIME-Version: 1.0 Received: by 10.100.20.39 with SMTP id 39mr1289599ant.6.1250545302120; Mon, 17 Aug 2009 14:41:42 -0700 (PDT) Date: Mon, 17 Aug 2009 14:41:42 -0700 (PDT) In-Reply-To: X-IP: 77.249.52.222 References: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2,gzip(gfe),gzip(gfe) Message-ID: Subject: Re: response is empty From: Hongli Lai To: Rack Development Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com On Aug 16, 5:19=A0pm, flyerhzm wrote: > I wrote a middleware in rails. The codes is like: > > =A0 def initialize(app) > =A0 =A0 @app =3D app > =A0 end > > =A0 def call(env) > =A0 =A0 status, headers, response =3D @app.call(env) > =A0 =A0 return [status, headers, response] if response.empty? > =A0 =A0 # other logic codes > =A0 end > > When I refresh the page, the response will be empty. So I puts > response.inspect, it's an empty array. Why? > > So the other logic codes will not run, which need response.body. Is it > some reason about cache? How can I make response always not empty? According to the Rack spec: "The Body must respond to each and must only yield String values. The Body itself should not be an instance of String, as this will break in Ruby 1.9." In other words: the Body is *not* a string, and is usually an Array of string. When you call response.empty? you're actually checking whether the response is an empty array, and returning just that. You should figure out how to do what you want with only an #each method at your disposal.