trouble reading query string

1999-12-22 Thread Ken Y. Clark

i'm currently converting several CGI scripts into mod_perl modules, and
i'm having difficulty in one particular situation reading the variable
input (i.e., query string on a GET or STDIN on POST).  quick background: i
had a PerlHandler on the end of this request for a while, accepting input
like "/foo?arg1=xarg2=y" which would create a form w/posted data
(including binary info like .png, .gif, .jpg, and .mp3), save that data
and return a user to a location.  that was in the early stages of
developing this.  i'm now incorporating a more realistic shell around my
dynamic output, one that show our ads which are proxy calls to a netscape
ad server.

my solution was to create a basic HTML page that has a simple perl sub on
it, like so:

!--File: foo.shtml --
html
head
title My Dynamic Page /title
/head

body
!--#AD CALL --
!--#perl sub="Foo::Bar" --
!--#MORE AD CALLS --
/body
/html

a user gets to this page by clicking on a link like this:
"/foo.shtml?arg1=xarg2=y".  my module starts off like this:

my $r = shift;
$r = $r-is_main ? $r : $r-main;
my %args = ($r-method_number == M_GET) ? $r-args : $r-content;

but when i went from having the PerlHandler doing everything to having the
module being called like an SSI call, %args doesn't get populated anymore.  
so i tried a hack i've done before with CGI.pm, like this:

unless (%args) {
my $q = CGI-new;
my @names = $q-param;
$args{$_} = $q-param($_) for @names;
}

but now, even this doesn't work, so i've had to put one more hack in, like
this:

unless (%args) {
my $original_request = $r-the_request;
my ($query_string)   = ($original_request =~ m/\?(.*?)\s+HTTP.*/);
my $q = CGI-new($query_string);
my @names = $q-param;
$args{$_} = $q-param($_) for @names;
}

so it now works, but i feel kinda dirty.  and here's the last bit of
strangeness:  i have another page that is generated in the same manner
that works just fine.  the only difference is that the perl sub generates
a form that is *not* enctype="multipart/form-data".  both forms do,
however, POST their data.

any ideas why things are behaving so strangely?  is my hack as
objectionable as i think it is?

ky




Re: trouble reading query string

1999-12-22 Thread Dmitry Beransky

At 11:52 AM 12/22/99 , Ken Y. Clark wrote:

so it now works, but i feel kinda dirty.  and here's the last bit of
strangeness:  i have another page that is generated in the same manner
that works just fine.  the only difference is that the perl sub generates
a form that is *not* enctype="multipart/form-data".  both forms do,
however, POST their data.

I'm not sure if I completely understand the problem at hand, but part of 
it, I think, is in trying to use $r-content with multipart/form-data data 
encoding.  $r-content only works with application/x-www-form-urlencoded 
data (see the documentation for Apache.pm).  To retrieve POSTed data in a 
multipart format you need to use $r-read or Apache::Request (see the docs 
for details).

Cheers
Dmitry