You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Rob Bloodgood <ro...@empire2.com> on 2001/06/20 20:11:25 UTC

Adding parameters to a request

OK, I've reviewed the code, looked at the docs, but I'm getting nowhere.

In my AuthenHandler, I run the following snippet:

	# validation successful
	$apr->subprocess_env(REMOTE_PASSWORD => $pass);
      my $args = $apr->args || '';
	$apr->args( $args . ( length $args ? '&' : '' ) . "pid=$pid" )
           unless $args =~ /pid=\d+/;
	return OK;

The intent is to add the parameter 'pid=99' or whatever to the request if it
is not already present.

It feels clunky and forced to me... is there a better way to do this?  As
indicated by the variable, I'm using Apache::Request, for the sole purpose
of having easier access to the parameters.  Except that it turns out
Apache::Request's param() method does NOT support *setting* parameters, only
*getting* them. <sigh>

THEN somebody on mod_perl told me to try parms(), which led to:

    my $parms = $apr->parms;
    $parms->add( pid => $pid) unless defined $parms->get('pid');

    #	$args = $apr->args;
    #$apr->args($parms);
    $apr->parms($parms);

    #$apr->param(pid => $pid);
    #$apr->param(pid => [$pid]);
    #warn (Dumper [ {$apr->args}, $x, $apr->query_string ] );

    if (! defined $apr->param('pid')) {
	$apr->args( $args . ( length $args ? '&' : '' ) . "pid=$pid" ) 			unless
$args =~ /pid=\d+/;
    } else {
	#warn "param pid is DEFINED!!! : ", $apr->param('pid');
	$apr->args( $args . ( length $args ? '&' : '' ) . "pid=$pid" ) 			unless
$args =~ /pid=\d+/;
    }


As should be obvious, even when the Apache::Table $parms was coaxed into
accepting the value for pid, my HTML::Mason pages still bitched about the
missing parameter, and I had to do what I'd been doing all along, to fix it.

Am I doing something wrong?  Am I expecting functionality that is just plain
*not* supported?

TIA!

L8r,
Rob



Re: Adding parameters to a request

Posted by Joe Schaefer <jo...@sunstarsys.com>.
"Rob Bloodgood" <ro...@empire2.com> writes:

> OK, I've reviewed the code, looked at the docs, but I'm getting nowhere.
> 
> In my AuthenHandler, I run the following snippet:
> 
> 	# validation successful
> 	$apr->subprocess_env(REMOTE_PASSWORD => $pass);
>       my $args = $apr->args || '';
> 	$apr->args( $args . ( length $args ? '&' : '' ) . "pid=$pid" )
>            unless $args =~ /pid=\d+/;
> 	return OK;
> 
> The intent is to add the parameter 'pid=99' or whatever to the request if it
> is not already present.
> 
> It feels clunky and forced to me... is there a better way to do this?  As
> indicated by the variable, I'm using Apache::Request, for the sole purpose
> of having easier access to the parameters.  Except that it turns out
> Apache::Request's param() method does NOT support *setting* parameters, only
> *getting* them. <sigh>

Sure it does-

  $apr->param(pid => $pid);

will set the parameter, as will

  $apr->param(pid => [$pid]);

they do slightly different things when there's already a pid in
the param table.  It's a bug if that is not what happens.

I would guess that you need to call Apache::Request->instance
instead of Apache::Request->new in your Mason code. The instance
method allows you to work with the same Apache::Request data 
across different phases of the request; new() doesn't.

I think what is happening is that you are making Apache::Request
parse the upload data in the AuthenHandler phase, which evacuates
all data from the pov of the content handler.  Either don't use
Apache::Request in your AuthenHandler, or use Apache::Request->instance 
in your Mason script.

HTH
-- 
Joe Schaefer