----- Original Message -----
From: "Matt" <matt / greenviolet.net>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Thursday, August 02, 2001 8:39 PM
Subject: [ruby-talk:19036] Re: YAWN Question (Your Annoying Wandering
Newbie)


> On Fri, 3 Aug 2001, David Tillman wrote:
>
> >   the_method = (ENV['QUERY_STRING'] and (cgi.params.length > 0)) ? 'GET'
: 'POST'
>
> Very cool. That's what I was looking for. I just couldn't get the syntax
correct. I'd test it to be sure, but apache isn't letting me run cgis.
(again...) I'll let you know if I have problems with it.

It is cool ;) and I used such logic some time ago - but it is completely
wrong. It works right in most cases, but really even a POST request may have
a query string.
Consider this request:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
POST /form.html?param=value HTTP/1.1
Host: server.domain.com
Content-Length: 13

param2=value2
<<<<<<<<<<<<<<<<<<<<<<<<<<<<

It is a valid HTTP/1.1 request, and server will set ENV['QUERY_STRING'] to
'param=value', so your check will think it is a GET request. It isn't
correct, isn't it ? ;)
The check for ENV['CONTENT_LENGTH'] maybe better, because GET requests
usually do not contain any data and so Content-Length is either undefned or
zero.
So I recommend the following (which is still not correct - the only real way
to get a request method is having the server tell it to you):
the_method = ENV['CONTENT_LENGTH'].to_s.to_i.zero? ? 'GET' : 'POST'

P.S. I'm not a HTTP guru, that's just stuff I learned from my work (and fun
;) so maybe I'm not correct too.

Aristarkh A Zagorodnikov, Lead Programmer, W3D Group
http://www.w3d.ru /// xm / w3d.ru /// ICQ UIN 36987938