rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Hongli Lai <hongli@phusion.nl>
To: Rack Development <rack-devel@googlegroups.com>
Subject: Re: response is empty
Date: Mon, 17 Aug 2009 14:41:42 -0700 (PDT)	[thread overview]
Message-ID: <b1fbc0ec-80b8-4b3a-b975-410aa6279eeb@j21g2000yqe.googlegroups.com> (raw)
In-Reply-To: <d68a566a-bd5e-46e2-889e-06971f710cbe@v36g2000yqv.googlegroups.com>


On Aug 16, 5:19 pm, flyerhzm <flyer...@gmail.com> wrote:
> I wrote a middleware in rails. The codes is like:
>
>   def initialize(app)
>     @app = app
>   end
>
>   def call(env)
>     status, headers, response = @app.call(env)
>     return [status, headers, response] if response.empty?
>     # other logic codes
>   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.

  reply	other threads:[~2009-08-17 21:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-16 15:19 response is empty flyerhzm
2009-08-17 21:41 ` Hongli Lai [this message]
2009-08-18  1:25   ` flyerhzm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b1fbc0ec-80b8-4b3a-b975-410aa6279eeb@j21g2000yqe.googlegroups.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).