rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* response is empty
@ 2009-08-16 15:19 flyerhzm
  2009-08-17 21:41 ` Hongli Lai
  0 siblings, 1 reply; 3+ messages in thread
From: flyerhzm @ 2009-08-16 15:19 UTC (permalink / raw)
  To: Rack Development


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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: response is empty
  2009-08-16 15:19 response is empty flyerhzm
@ 2009-08-17 21:41 ` Hongli Lai
  2009-08-18  1:25   ` flyerhzm
  0 siblings, 1 reply; 3+ messages in thread
From: Hongli Lai @ 2009-08-17 21:41 UTC (permalink / raw)
  To: Rack Development


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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: response is empty
  2009-08-17 21:41 ` Hongli Lai
@ 2009-08-18  1:25   ` flyerhzm
  0 siblings, 0 replies; 3+ messages in thread
From: flyerhzm @ 2009-08-18  1:25 UTC (permalink / raw)
  To: Rack Development


I think it's the problem of cache because if I disabled browser cache,
the issue is fixed.

Thanks

On Aug 18, 5:41 am, Hongli Lai <hon...@phusion.nl> wrote:
> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-18  1:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-16 15:19 response is empty flyerhzm
2009-08-17 21:41 ` Hongli Lai
2009-08-18  1:25   ` flyerhzm

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).