You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Frank Maas <fr...@cheiron-it.nl> on 2005/05/06 14:54:04 UTC

[mp1] post2get and multipart/form-data

Hi,

After some time doing other things, I recently started to upgrade our
installation. While doing this I got the new version of CGI.pm that uses
XHMTL for default and, as a result, uses multipart/form-data as default
encoding...
Our websystem works in a 2-phase manner: a user requests an URI and the
server transforms this initial request in serving a SSI template. The 
original URI is included from this SSI (thus as a subrequest). To make
this work I convert POST requests to GET requests (so the parameters are
not lost, based on a Geoff-example) and make sure that they get populated 
to the subrequest (via a transhandler). This works... worked :-(
The content method of Apache.pm explicitly bails out if the form is not
send in the old way. Now I can get CGI.pm to do this (btw, this is not as
easy as it is described), but since I want to support uploads at one time
I must deal with the multipart thing.

Standard disclaimer: I tried to google this problem and searched throug
the mailinglist, but the only solutions I found used Apache::Request. And
I try to avoid using it because (a) it is heavy (is it?), (b) it eats POST
data in a way that CGI can no longer handle it properly, (c) if I want to
change to Apache2 every usage of APR must be rechecked.

So... any thoughts...?

Kind regards,

Frank

Re: [mp1] post2get and multipart/form-data

Posted by Stas Bekman <st...@stason.org>.
Frank Maas wrote:
> Hi Stas,
> 
> Thanks for responding.
> 
> 
>>>this work I convert POST requests to GET requests (so the parameters are
>>>not lost, based on a Geoff-example) and make sure that they get populated 
>>>to the subrequest (via a transhandler). This works... worked :-(
>>
>>what has changed since it was working?
> 
> 
> What changed was the way CGI.pm is working. Since some version in the
> history it started to use XHTML as default and with it Lincoln changed
> the default encoding to multipart/form-data. As I said, this behaviour
> can be changed, but that mechanism does not co-operate reliably with
> mod_perl. Anyhow, I gather that wanting to support uploads kind of makes
> it necessary to use multipart posts.

If CGI.pm has broken backwards compatibility, it's not a good thing. It 
should probably provide some flag to enable it. (Or may be the move to 3.0 
was intentional to allow new functionality, in which case, just continue 
using the latest CGI.pm in the 2.x series.

>>>I try to avoid using it because (a) it is heavy (is it?),
>>
>>you must be kidding, Frank. libapreq heavy? it's much lighter and faster 
>>than CGI.pm, check the benchmarks:
> 
> 
> Yep, sorry - didn't mean it lik that. I compared using APR to not using

APR is totally different thing, accessible only from mp2, you must have 
meant libapreq or Apache::Request.

> it at all. When I use CGI I do this because I "like" the way it handles 
> forms and allows me to perl-code HTML. It is possible however that I 
> turn away from CGI.pm as well though.

You can still use CGI.pm to produce output. And in libapreq2 (requires 
apache2), you will be able to re-use data, so you won't need to do any 
workarounds.

BTW, If you have further questions re: libapreq it's the best to send 
those to the libapreq dev mailing list.

>>>(b) it eats POST data in a way that CGI can no longer handle it properly, 
>>
>>right, which is why you should move to Apache2, where it doesn't happen.
>>
>>(c) if I want to change to Apache2 every usage of APR must be rechecked.
>>what do you mean?
> 
> 
> Combining the two: the last time I looked into using Apache2 was more than 
> half a year ago. At that time there was no Apache::Request and, contrary 
> to what you might deduce from my writing above, I use(d) it in rather a 
> lot of places. Oh and... I have your (and co-author)  Practical Guide to 
> mod_perl and Geoffs (and co-author) Cookbook, use those rather heavily and 
> lack good books on mp2. So perhaps I am also a bit afraid of the dark...

We will see, may be some mp2 docs will be published. For now mp2 has an 
extensive docs at: http://perl.apache.org/docs/2.0/index.html
and I believe so does libapreq, not sure if they are online.

> BTW - while speaking to you on this subject ;-): while searching for this 
> issue I found, on the perl.apache.org website 
> (http://perl.apache.org/docs/1.0/guide/snippets.html#Reusing_Data_from_POST_request)
> the text "But what do we do with large multipart file uploads? [...]
> switch the request method from POST to GET, and store the POST data 
> in the query string. This handler does exactly this:"
> AFAIK now this is incorrect. Seen the rest of the text, it should better 
> read:
> 
> "As long as you do not use multipart/form-data encoded POSTs (like with
> file uploads) you can also alter the request. A transparent..."
> 
> Do you agree? To whom and how should I send such a correction?

Hmm, it's been years since I've last used this code. As it's written, it's 
supposed to be the solution for the multipart encoded POSTs. You are 
suggesting the opposite. So why is it needed at all then?


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [mp1] post2get and multipart/form-data

Posted by Frank Maas <fr...@cheiron-it.nl>.
Hi Stas,

Thanks for responding.

> >this work I convert POST requests to GET requests (so the parameters are
> >not lost, based on a Geoff-example) and make sure that they get populated 
> >to the subrequest (via a transhandler). This works... worked :-(
> 
> what has changed since it was working?

What changed was the way CGI.pm is working. Since some version in the
history it started to use XHTML as default and with it Lincoln changed
the default encoding to multipart/form-data. As I said, this behaviour
can be changed, but that mechanism does not co-operate reliably with
mod_perl. Anyhow, I gather that wanting to support uploads kind of makes
it necessary to use multipart posts.

> >I try to avoid using it because (a) it is heavy (is it?),
> 
> you must be kidding, Frank. libapreq heavy? it's much lighter and faster 
> than CGI.pm, check the benchmarks:

Yep, sorry - didn't mean it lik that. I compared using APR to not using
it at all. When I use CGI I do this because I "like" the way it handles 
forms and allows me to perl-code HTML. It is possible however that I 
turn away from CGI.pm as well though.

> >(b) it eats POST data in a way that CGI can no longer handle it properly, 
> right, which is why you should move to Apache2, where it doesn't happen.
>
> (c) if I want to change to Apache2 every usage of APR must be rechecked.
> what do you mean?

Combining the two: the last time I looked into using Apache2 was more than 
half a year ago. At that time there was no Apache::Request and, contrary 
to what you might deduce from my writing above, I use(d) it in rather a 
lot of places. Oh and... I have your (and co-author)  Practical Guide to 
mod_perl and Geoffs (and co-author) Cookbook, use those rather heavily and 
lack good books on mp2. So perhaps I am also a bit afraid of the dark...


BTW - while speaking to you on this subject ;-): while searching for this 
issue I found, on the perl.apache.org website 
(http://perl.apache.org/docs/1.0/guide/snippets.html#Reusing_Data_from_POST_request)
the text "But what do we do with large multipart file uploads? [...]
switch the request method from POST to GET, and store the POST data 
in the query string. This handler does exactly this:"
AFAIK now this is incorrect. Seen the rest of the text, it should better 
read:

"As long as you do not use multipart/form-data encoded POSTs (like with
file uploads) you can also alter the request. A transparent..."

Do you agree? To whom and how should I send such a correction?

Bye!
Frank


Re: [mp1] post2get and multipart/form-data

Posted by Stas Bekman <st...@stason.org>.
Frank Maas wrote:
> Hi,
> 
> After some time doing other things, I recently started to upgrade our
> installation. While doing this I got the new version of CGI.pm that uses
> XHMTL for default and, as a result, uses multipart/form-data as default
> encoding...
> Our websystem works in a 2-phase manner: a user requests an URI and the
> server transforms this initial request in serving a SSI template. The 
> original URI is included from this SSI (thus as a subrequest). To make
> this work I convert POST requests to GET requests (so the parameters are
> not lost, based on a Geoff-example) and make sure that they get populated 
> to the subrequest (via a transhandler). This works... worked :-(

what has changed since it was working?

> The content method of Apache.pm explicitly bails out if the form is not
> send in the old way. Now I can get CGI.pm to do this (btw, this is not as
> easy as it is described), but since I want to support uploads at one time
> I must deal with the multipart thing.
> 
> Standard disclaimer: I tried to google this problem and searched throug
> the mailinglist, but the only solutions I found used Apache::Request. And
> I try to avoid using it because (a) it is heavy (is it?),

you must be kidding, Frank. libapreq heavy? it's much lighter and faster 
than CGI.pm, check the benchmarks:
http://modperlbook.org/html/ch13_02.html

> (b) it eats POST data in a way that CGI can no longer handle it properly, 

right, which is why you should move to Apache2, where it doesn't happen.

(c) if I want to change to Apache2 every usage of APR must be rechecked.

what do you mean?


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com