# Mod\_ruby Apache2 Accessing POSTed Data More than Once

**URL:** <https://www.ruby-forum.com/t/mod-ruby-apache2-accessing-posted-data-more-than-once/48082>\
**Category:** Ruby\
**Created:** [November 16, 2005, 5:47pm UTC](https://www.ruby-forum.com/t/mod-ruby-apache2-accessing-posted-data-more-than-once/48082 "2005-11-16T17:47:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubytalk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9fc29f/32.png) [@rubytalk](https://www.ruby-forum.com/u/rubytalk)\
**Post date:** [November 16, 2005, 5:47pm UTC](https://www.ruby-forum.com/t/mod-ruby-apache2-accessing-posted-data-more-than-once/48082/1 "2005-11-16T17:47:53Z")

</div>

(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

```
<%
puts Apache.request.read # expected data
puts Apache.request.read # nil
puts Apache.request.read # nil
%>
```

---

<div class="post-metadata">

**Author:** ![rubytalk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9fc29f/32.png) [@rubytalk](https://www.ruby-forum.com/u/rubytalk)\
**Post date:** [November 16, 2005, 6:39pm UTC](https://www.ruby-forum.com/t/mod-ruby-apache2-accessing-posted-data-more-than-once/48082/2 "2005-11-16T18:39:13Z")

</div>

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](http://www.ruby-doc.org) - Ruby Help & Documentation  
[Ruby Code & Style](http://www.artima.com/rubycs/) - Ruby Code & Style: Writers wanted  
[http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys  
[http://www.30secondrule.com](http://www.30secondrule.com) - Building Better Tools
