Forum: Ruby mod_ruby Apache2 Accessing POSTed Data More than Once

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B013a92b64915f94d1fe5854277ce624?d=identicon&s=25 rubytalk (Guest)
on 2005-11-16 17:47
(Received via mailing list)
(Moving the below over from mod_ruby to the larger audience on
ruby-talk.)
Hi,

Our complex custom template system requires a file containing a class
called Page. Depending on the particular configuration of a given page,
Page can get initialized several times. Page has a method to fetch CGI
parameters (calls @cgi.params.dup where @cgi has been initialized to
CGI.new). The first time this method is called, things work. Subsequent
calls don't work under Ubuntu 5.04/Ruby 1.8(libapache2-mod-ruby
1.2.4-1)/Apache2. They did under Debian 3.0/Ruby1.6/Apahce1.3.

I tried setting a class variable with cgi.params the first time Page is
initialized. This didn't work because we're using mod_ruby and Apache2
which caches code in memory between requests.

Digging down to the mod_ruby level (bypassing CGI):
If I submit data using the example below, the first Apache.request.read
returns the POSTed data while subsequent calls return nil instead of
repeating the POSTed data. So, we get the same problem as we do with
CGI.

Using multiple instances of CGI or directly via mod_ruby, how do I
access POSTed data more than one time from a script?

Thank you,
Ben Gribaudo

<pre>
<%
puts Apache.request.read # expected data
puts Apache.request.read # nil
puts Apache.request.read # nil
%>
</pre>
<form method="post">
<input type="text" name="test" />
<input type="submit" />
</form>
Bc6d88907ce09158581fbb9b469a35a3?d=identicon&s=25 james_b (Guest)
on 2005-11-16 18:39
(Received via mailing list)
Ben Gribaudo wrote:
..
> Using multiple instances of CGI or directly via mod_ruby, how do I
> access POSTed data more than one time from a script?
>


Here's a guess: request.reset

I have no means to test this, but maybe request is acting like an IO
object which must be reset after a read.

James

--

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
http://www.rubystuff.com      - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com     - Playing with Better Toys
http://www.30secondrule.com   - Building Better Tools
This topic is locked and can not be replied to.