rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* Rack::ETag does not set headers for Array type response bodies
@ 2010-03-04 13:17 Karel Minarik
  2010-03-04 15:48 ` Ryan Tomayko
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Minarik @ 2010-03-04 13:17 UTC (permalink / raw)
  To: Rack Development

Hi,

I wanted to `use Rack::ETag` from rack-contrib [1] to automatically
set ETag headers in a Sinatra application, and discovered that it
checks whether the response body is a String. Since Rack response
bodies are _specifically_ required to _not_ be an instance of String
-- as far as I understand [2] -- and eg. Sinatra serves an Array by
default [3], this fails.

The solution would be to just call `body.to_s`, as you can see in this
commit: [4]. I am not sure how it would affect streaming responses,
but the current implementation of Rack::ETag is more or less useless
in Sinatra /and possibly elsewhere/.

Karel

[1] http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/etag.rb
[2] http://rack.rubyforge.org/doc/files/SPEC.html
[3] http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L57-62
[4] http://github.com/karmi/rack-contrib/commit/56f02f3e294cece010caed7865581ba63be6f868#diff-0

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

* Re: Rack::ETag does not set headers for Array type response bodies
  2010-03-04 13:17 Rack::ETag does not set headers for Array type response bodies Karel Minarik
@ 2010-03-04 15:48 ` Ryan Tomayko
  2010-03-04 17:49   ` Karel Minarik
  0 siblings, 1 reply; 3+ messages in thread
From: Ryan Tomayko @ 2010-03-04 15:48 UTC (permalink / raw)
  To: rack-devel

On Thu, Mar 4, 2010 at 5:17 AM, Karel Minarik <karel.minarik@gmail.com> wrote:
> Hi,
>
> I wanted to `use Rack::ETag` from rack-contrib [1] to automatically
> set ETag headers in a Sinatra application, and discovered that it
> checks whether the response body is a String. Since Rack response
> bodies are _specifically_ required to _not_ be an instance of String
> -- as far as I understand [2] -- and eg. Sinatra serves an Array by
> default [3], this fails.
>
> The solution would be to just call `body.to_s`, as you can see in this
> commit: [4]. I am not sure how it would affect streaming responses,
> but the current implementation of Rack::ETag is more or less useless
> in Sinatra /and possibly elsewhere/.
>
> Karel
>
> [1] http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/etag.rb
> [2] http://rack.rubyforge.org/doc/files/SPEC.html
> [3] http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L57-62
> [4] http://github.com/karmi/rack-contrib/commit/56f02f3e294cece010caed7865581ba63be6f868#diff-0
>

Rack::ETag has been a part of Rack core for a while now:

http://github.com/rack/rack/blob/master/lib/rack/etag.rb

It fixes the issues mentioned. I'll remove the version contrib.

Thanks,
Ryan

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

* Re: Rack::ETag does not set headers for Array type response bodies
  2010-03-04 15:48 ` Ryan Tomayko
@ 2010-03-04 17:49   ` Karel Minarik
  0 siblings, 0 replies; 3+ messages in thread
From: Karel Minarik @ 2010-03-04 17:49 UTC (permalink / raw)
  To: Rack Development

Argh, thanks, Ryan!!

Karel

On Mar 4, 4:48 pm, Ryan Tomayko <r...@tomayko.com> wrote:
> On Thu, Mar 4, 2010 at 5:17 AM, Karel Minarik <karel.mina...@gmail.com> wrote:
> > Hi,
>
> > I wanted to `use Rack::ETag` from rack-contrib [1] to automatically
> > set ETag headers in a Sinatra application, and discovered that it
> > checks whether the response body is a String. Since Rack response
> > bodies are _specifically_ required to _not_ be an instance of String
> > -- as far as I understand [2] -- and eg. Sinatra serves an Array by
> > default [3], this fails.
>
> > The solution would be to just call `body.to_s`, as you can see in this
> > commit: [4]. I am not sure how it would affect streaming responses,
> > but the current implementation of Rack::ETag is more or less useless
> > in Sinatra /and possibly elsewhere/.
>
> > Karel
>
> > [1]http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/etag.rb
> > [2]http://rack.rubyforge.org/doc/files/SPEC.html
> > [3]http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L57-62
> > [4]http://github.com/karmi/rack-contrib/commit/56f02f3e294cece010caed786...
>
> Rack::ETag has been a part of Rack core for a while now:
>
> http://github.com/rack/rack/blob/master/lib/rack/etag.rb
>
> It fixes the issues mentioned. I'll remove the version contrib.
>
> Thanks,
> Ryan

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

end of thread, other threads:[~2010-03-04 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-04 13:17 Rack::ETag does not set headers for Array type response bodies Karel Minarik
2010-03-04 15:48 ` Ryan Tomayko
2010-03-04 17:49   ` Karel Minarik

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