modperl-persistant_post_info

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



To: <modperl@apache.org>
From: "Issac Goldstand" <margol@beamartyr.net>
Subject: Keeping POST information between request phases
Date: Sun, 30 Sep 2001 17:59:08 +0200

I know this sounds like a rather newbie-ish question, but I guess I =
never really did many inter-request-phase stuff before...  Anyway, how =
can I keep track of the information from a POST request between =
different phases of Apache's handling?  For example, if I have a =
$q=3Dnew Apache::Request($r); in, say, the Authentication, how can I get =
the POSTed variables in, say, the Response phase?

===

To: Issac Goldstand <margol@beamartyr.net>
From: Thomas Eibner <thomas@stderr.net>
Subject: Re: Keeping POST information between request phases
Date: Sun, 30 Sep 2001 18:15:43 +0200

On Sun, Sep 30, 2001 at 05:59:08PM +0200, Issac Goldstand wrote:
> I know this sounds like a rather newbie-ish question, but I guess I never really did many inter-request-phase stuff before...  Anyway, how can I keep track of the information from a POST request between different phases of Apache's handling?  For example, if I have a $q=new Apache::Request($r); in, say, the Authentication, how can I get the POSTed variables in, say, the Response phase?

Use the "newly" introduced instance function of Apache::Request :

my $apr = Apache::Request->instance($r);

===

To: Thomas Eibner <thomas@stderr.net>
From: Alin Simionoiu <asimionoiu@musicnet.com>
Subject: Re: Keeping POST information between request phases
Date: 30 Sep 2001 15:23:51 -0700

Apache::Request->instance($r) will not work for POST reqests.
At list will not do what you want.

Read this for more information:

http://perl.apache.org/guide/snippets.html#Reusing_Data_from_POST_request

===

To: Alin Simionoiu <asimionoiu@musicnet.com>
From: Thomas Eibner <thomas@stderr.net>
Subject: Re: Keeping POST information between request phases
Date: Mon, 1 Oct 2001 19:35:32 +0200

On Sun, Sep 30, 2001 at 03:23:51PM -0700, Alin Simionoiu wrote:
> Apache::Request->instance($r) will not work for POST reqests.
> At list will not do what you want.

Apache::Request->instance works very well with POST requests.

>From the documentation:

  instance

  The instance() class method allows Apache::Request to
  be a singleton.  This means that whenever you call
  Apache::Request->instance() within a single request
  you always get the same Apache::Request object back.
  This solves the problem with creating the
  Apache::Request object twice within the same request -
  the symptoms being that the second Apache::Request
  object will not contain the form parameters because
  they have already been read and parsed.

  my $apr = Apache::Request->instance($r, DISABLE_UPLOADS => 1);

  Note that "instance()" call will take the same parame-
  ters as the above call to "new()", however the parame-
  ters will only have an effect the first time
  "instance()" is called within a single request. Extra
  parameters will be ignored on subsequent calls to
  "instance()" within the same request.

> Read this for more information:
> 
> http://perl.apache.org/guide/snippets.html#Reusing_Data_from_POST_request

Above instance method was made to avoid having to do workarounds like
that in the guide.

===

To: Thomas Eibner <thomas@stderr.net>
From: Alin Simionoiu <asimionoiu@musicnet.com>
Subject: Re: Keeping POST information between request phases
Date: 30 Sep 2001 16:03:43 -0700

I tried instance, but is not working is you want to access let's say,
POST data in a authentication handler, doing same data validation or
whatever you want to do, and also access the same POST data at response
phase.

And this is because, as it is explained in guide, POST data are
retrieved directly from the socket.So once you read that, is gone.

The only way to keep this around that I know about is to internally
transform POST in a GET.

For sure this is not the best solution, specially if you have large POST
body, because you can exceed GET maximum length.

===


To: Alin Simionoiu <asimionoiu@musicnet.com>
From: Thomas Eibner <thomas@stderr.net>
Subject: Re: Keeping POST information between request phases
Date: Mon, 1 Oct 2001 20:21:59 +0200

On Sun, Sep 30, 2001 at 04:03:43PM -0700, Alin Simionoiu wrote:
> I tried instance, but is not working is you want to access let's say,
> POST data in a authentication handler, doing same data validation or
> whatever you want to do, and also access the same POST data at response
> phase.
> 
> And this is because, as it is explained in guide, POST data are
> retrieved directly from the socket.So once you read that, is gone.
> 
> The only way to keep this around that I know about is to internally
> transform POST in a GET.

And then the method that Apache::Requets->instance uses.

actual code:
sub instance {
    my $class = shift;
    my $r = shift;
    if (my $apreq = $r->pnotes('apreq')) {
        return $apreq;
    }
    my $new_req = $class->new($r, @_);
    $r->pnotes('apreq', $new_req);
    return $new_req;
}

Which means you're only calling Apache::Request->new once and therefore
only reading from the socket once. This is stored in the pnotes table
in the Apache request object and follows all the way through the request
and will make POST's work from both your AuthenHandler and your content
handler in the same request.

===

To: "'Alin Simionoiu'" <asimionoiu@musicnet.com>,
From: Geoffrey Young <gyoung@laserlink.net>
Subject: RE: Keeping POST information between request phases
Date: Mon, 1 Oct 2001 14:25:41 -0400 

> -----Original Message-----
> From: Alin Simionoiu [mailto:asimionoiu@musicnet.com]
> Sent: Sunday, September 30, 2001 7:04 PM
> To: Thomas Eibner
> Cc: Issac Goldstand; modperl@apache.org
> Subject: Re: Keeping POST information between request phases
> 
> 
> I tried instance, but is not working is you want to access let's say,
> POST data in a authentication handler, doing same data validation or
> whatever you want to do, and also access the same POST data 
> at response
> phase.

there must be a problem with your setup then - this is _exactly_ why
instance() was created.  It came out of discussions about
Apache::RequestNotes, which solves this exact issue.  Matt and Jim decided
that the functionality of Apache::RequestNotes probably belonged in
Apache::Request proper, hence instance().

> 
> And this is because, as it is explained in guide, POST data are
> retrieved directly from the socket.So once you read that, is gone.
> 
> The only way to keep this around that I know about is to internally
> transform POST in a GET.

no.  Apache::RequestNotes and instance() are far better solutions.  with
those you only pass around a reference to the POST data, which is cleaner.
furthermore, Apache::Request only parses POST once you call param(), not
when you call instance() or new(), which is an extra savings.

> 
> For sure this is not the best solution, specially if you have 
> large POST
> body, because you can exceed GET maximum length.

that's why there is Apache::Request :)

====


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu