rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* Patch: Make CGI handler obey rack spec for the greater good
@ 2010-05-12 13:24 Max Cantor
  2010-05-20 14:09 ` James Tucker
  0 siblings, 1 reply; 8+ messages in thread
From: Max Cantor @ 2010-05-12 13:24 UTC (permalink / raw)
  To: rack-devel

The default CGI handler included in rack doesn't obey the rack spec;
its input stream is not rewindable, and thus generates Errno::ESPIPE
illegal seek errors.  You can see the Sinatra guys needed a workaround
for it here: https://sinatra.lighthouseapp.com/projects/9779/tickets/227-errnoespipe-illegal-seek-with-cgi-sinatra

This patch wraps the CGI handler's input stream in a rewindable input
object, which makes the handler adhere to the rack spec.

http://github.com/visudo/rack/commit/0ca92960d4d9e2e79d31028b3383f0bde7230344

 - Max Cantor
Developer, Designer & Web Specialist
(216) 539-5836
http://inspiranity.com

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

* Re: Patch: Make CGI handler obey rack spec for the greater good
  2010-05-12 13:24 Patch: Make CGI handler obey rack spec for the greater good Max Cantor
@ 2010-05-20 14:09 ` James Tucker
  2010-05-20 17:36   ` Max Cantor
  2010-06-29 10:27   ` Hongli Lai
  0 siblings, 2 replies; 8+ messages in thread
From: James Tucker @ 2010-05-20 14:09 UTC (permalink / raw)
  To: rack-devel


On 12 May 2010, at 10:24, Max Cantor wrote:

> The default CGI handler included in rack doesn't obey the rack spec;
> its input stream is not rewindable, and thus generates Errno::ESPIPE
> illegal seek errors.  You can see the Sinatra guys needed a workaround
> for it here: https://sinatra.lighthouseapp.com/projects/9779/tickets/227-errnoespipe-illegal-seek-with-cgi-sinatra
> 
> This patch wraps the CGI handler's input stream in a rewindable input
> object, which makes the handler adhere to the rack spec.

Didn't we say this was optional in the spec?

This could be a middleware, as has been discussed elsewhere on this ML in the last 6 months.

> 
> http://github.com/visudo/rack/commit/0ca92960d4d9e2e79d31028b3383f0bde7230344
> 
> - Max Cantor
> Developer, Designer & Web Specialist
> (216) 539-5836
> http://inspiranity.com

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

* Re: Patch: Make CGI handler obey rack spec for the greater good
  2010-05-20 14:09 ` James Tucker
@ 2010-05-20 17:36   ` Max Cantor
  2010-05-20 21:10     ` James Tucker
  2010-06-29 10:27   ` Hongli Lai
  1 sibling, 1 reply; 8+ messages in thread
From: Max Cantor @ 2010-05-20 17:36 UTC (permalink / raw)
  To: Rack Development



On May 20, 10:09 am, James Tucker <jftuc...@gmail.com> wrote:
> On 12 May 2010, at 10:24, Max Cantor wrote:
>
> > The default CGI handler included in rack doesn't obey the rack spec;
> > its input stream is not rewindable, and thus generates Errno::ESPIPE
> > illegal seek errors.  You can see the Sinatra guys needed a workaround
> > for it here:https://sinatra.lighthouseapp.com/projects/9779/tickets/227-errnoespi...
>
> > This patch wraps the CGI handler's input stream in a rewindable input
> > object, which makes the handler adhere to the rack spec.
>
> Didn't we say this was optional in the spec?
>
> This could be a middleware, as has been discussed elsewhere on this ML in the last 6 months.


From the spec at http://rack.rubyforge.org/doc/SPEC.html:

> The input stream is an IO-like object which contains the raw HTTP POST data. When applicable, its external encoding must be “ASCII-8BIT” and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to gets, each, read and rewind.

> rewind must be called without arguments. It rewinds the input stream back to the beginning. It must not raise Errno::ESPIPE: that is, it may not be a pipe or a socket. Therefore, handler developers must buffer the input data into some rewindable object if the underlying input stream is not rewindable.

Perhaps it is out of date or I am interpreting it incorrectly, but I
took the "must" in those paragraphs to heart--my mistake if I'm
reading the wrong part of the spec or something.

Do you feel like there's a good reason to not make the CGI handler's
input stream rewindable?  Every time I update rack, I have to re-patch
it myself, because it never works.  It seems pretty unintuitive to
require adding middleware just to make the CGI handler work at all.

 - Max

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

* Re: Patch: Make CGI handler obey rack spec for the greater good
  2010-05-20 17:36   ` Max Cantor
@ 2010-05-20 21:10     ` James Tucker
  2010-06-12 18:46       ` Max Cantor
  0 siblings, 1 reply; 8+ messages in thread
From: James Tucker @ 2010-05-20 21:10 UTC (permalink / raw)
  To: rack-devel


On 20 May 2010, at 14:36, Max Cantor wrote:

> 
> 
> On May 20, 10:09 am, James Tucker <jftuc...@gmail.com> wrote:
>> On 12 May 2010, at 10:24, Max Cantor wrote:
>> 
>>> The default CGI handler included in rack doesn't obey the rack spec;
>>> its input stream is not rewindable, and thus generates Errno::ESPIPE
>>> illegal seek errors.  You can see the Sinatra guys needed a workaround
>>> for it here:https://sinatra.lighthouseapp.com/projects/9779/tickets/227-errnoespi...
>> 
>>> This patch wraps the CGI handler's input stream in a rewindable input
>>> object, which makes the handler adhere to the rack spec.
>> 
>> Didn't we say this was optional in the spec?
>> 
>> This could be a middleware, as has been discussed elsewhere on this ML in the last 6 months.
> 
> 
> From the spec at http://rack.rubyforge.org/doc/SPEC.html:
> 
>> The input stream is an IO-like object which contains the raw HTTP POST data. When applicable, its external encoding must be “ASCII-8BIT” and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to gets, each, read and rewind.
> 
>> rewind must be called without arguments. It rewinds the input stream back to the beginning. It must not raise Errno::ESPIPE: that is, it may not be a pipe or a socket. Therefore, handler developers must buffer the input data into some rewindable object if the underlying input stream is not rewindable.
> 
> Perhaps it is out of date or I am interpreting it incorrectly, but I
> took the "must" in those paragraphs to heart--my mistake if I'm
> reading the wrong part of the spec or something.

Nope, maybe it just went the other way last time this discussion came up and I forgot.

> Do you feel like there's a good reason to not make the CGI handler's
> input stream rewindable?  Every time I update rack, I have to re-patch
> it myself, because it never works.  It seems pretty unintuitive to
> require adding middleware just to make the CGI handler work at all.

I just don't see really good reasons to buffer for the sake of buffering.

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

* Re: Patch: Make CGI handler obey rack spec for the greater good
  2010-05-20 21:10     ` James Tucker
@ 2010-06-12 18:46       ` Max Cantor
  2010-06-13 21:11         ` James Tucker
  0 siblings, 1 reply; 8+ messages in thread
From: Max Cantor @ 2010-06-12 18:46 UTC (permalink / raw)
  To: Rack Development

On May 20, 5:10 pm, James Tucker <jftuc...@gmail.com> wrote:
> On 20 May 2010, at 14:36, Max Cantor wrote:
> > Do you feel like there's a good reason to not make the CGI handler's
> > input stream rewindable?  Every time I update rack, I have to re-patch
> > it myself, because it never works.  It seems pretty unintuitive to
> > require adding middleware just to make the CGI handler work at all.
>
> I just don't see really good reasons to buffer for the sake of buffering.

I'm not suggesting that we buffer for the sake of buffering... the CGI
handler literally does not work for me without this patch.  I don't
think I'm doing anything very idiosyncratic: Just a basic rack app
with lighttpd.  If there's some way I can reconfigure my environment
to obviate the need for this patch, I can do that, but it seems like
the handler's lack of adherence to the spec is making it break.

 - Max

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

* Re: Patch: Make CGI handler obey rack spec for the greater good
  2010-06-12 18:46       ` Max Cantor
@ 2010-06-13 21:11         ` James Tucker
  0 siblings, 0 replies; 8+ messages in thread
From: James Tucker @ 2010-06-13 21:11 UTC (permalink / raw)
  To: rack-devel


On 12 Jun 2010, at 15:46, Max Cantor wrote:

> On May 20, 5:10 pm, James Tucker <jftuc...@gmail.com> wrote:
>> On 20 May 2010, at 14:36, Max Cantor wrote:
>>> Do you feel like there's a good reason to not make the CGI handler's
>>> input stream rewindable?  Every time I update rack, I have to re-patch
>>> it myself, because it never works.  It seems pretty unintuitive to
>>> require adding middleware just to make the CGI handler work at all.
>> 
>> I just don't see really good reasons to buffer for the sake of buffering.
> 
> I'm not suggesting that we buffer for the sake of buffering... the CGI
> handler literally does not work for me without this patch.  I don't
> think I'm doing anything very idiosyncratic: Just a basic rack app
> with lighttpd.  If there's some way I can reconfigure my environment
> to obviate the need for this patch, I can do that, but it seems like
> the handler's lack of adherence to the spec is making it break.

The spec went the way of requiring rewind. I'm not sure what the conditions are that $stdin isn't rewindable, but your patch is valid to solve the problem. Sadly, it just missed release :-/

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

* Re: Patch: Make CGI handler obey rack spec for the greater good
  2010-05-20 14:09 ` James Tucker
  2010-05-20 17:36   ` Max Cantor
@ 2010-06-29 10:27   ` Hongli Lai
  2010-06-29 10:44     ` James Tucker
  1 sibling, 1 reply; 8+ messages in thread
From: Hongli Lai @ 2010-06-29 10:27 UTC (permalink / raw)
  To: Rack Development

On May 20, 4:09 pm, James Tucker <jftuc...@gmail.com> wrote:
> Didn't we say this was optional in the spec?
>
> This could be a middleware, as has been discussed elsewhere on this ML in the last 6 months.

No. Rewindability was made a hard requirement for the 1.0 spec because
there are too many apps and frameworks out there that try to rewind
rack.input.

The consensus on this mailing list was to get rid of the rewindability
requirement for the 2.0 spec and that future apps/frameworks should
just fix their code to not rely on rewindability.

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

* Re: Patch: Make CGI handler obey rack spec for the greater good
  2010-06-29 10:27   ` Hongli Lai
@ 2010-06-29 10:44     ` James Tucker
  0 siblings, 0 replies; 8+ messages in thread
From: James Tucker @ 2010-06-29 10:44 UTC (permalink / raw)
  To: rack-devel


On 29 Jun 2010, at 07:27, Hongli Lai wrote:

> On May 20, 4:09 pm, James Tucker <jftuc...@gmail.com> wrote:
>> Didn't we say this was optional in the spec?
>> 
>> This could be a middleware, as has been discussed elsewhere on this ML in the last 6 months.
> 
> No. Rewindability was made a hard requirement for the 1.0 spec because
> there are too many apps and frameworks out there that try to rewind
> rack.input.
> 
> The consensus on this mailing list was to get rid of the rewindability
> requirement for the 2.0 spec and that future apps/frameworks should
> just fix their code to not rely on rewindability.


Ah cool, thanks for the summary, the details obviously slipped my mind completely!

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

end of thread, other threads:[~2010-06-29 10:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-12 13:24 Patch: Make CGI handler obey rack spec for the greater good Max Cantor
2010-05-20 14:09 ` James Tucker
2010-05-20 17:36   ` Max Cantor
2010-05-20 21:10     ` James Tucker
2010-06-12 18:46       ` Max Cantor
2010-06-13 21:11         ` James Tucker
2010-06-29 10:27   ` Hongli Lai
2010-06-29 10:44     ` James Tucker

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