You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by pe...@peter.nyc.ny.us on 2001/05/31 01:00:17 UTC

problem with Apache::Request, multipart/form-data, and large TEXTAREAs?

Hello-

I've noticed a problem when i try to POST large
TEXTAREA fields with ENCTYPE=multipart/form-data and
read it with Apache::Request.

It seems like when the data is between roughly
5K-10Kbytes, i get extra garbage at the end. When it's
greater than 10K, it gets chopped between ~5K-10K
bytes. Sounds like some 5K buffer somewhere getting
mangled. (Note, file uploads work fine, and I don't
have these problems with TEXTAREAs without the
ENCTYPE....)

I have my test code below for illustration. Also,
CGI.pm works fine-- parseFormCGI instead of
parseFormApache below. (BTW, I'm running mod_perl 1.25
w/ Apache 1.3.20 and perl 5.6.1 on linux 2.4.2-2.)

Has anyone encountered this before? Any help is greatly
appreciated.

TIA,
peter
peter@peter.nyc.ny.us



------------------------------------------- form:

<FORM ACTION=/test METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE=SUBMIT VALUE=GO!><BR>
<TEXTAREA NAME=FOO COLS=120 ROWS=30>
0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........
0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........
   [...repeat ~100 times...]
0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........
</TEXTAREA>
</FORM>

------------------------------------------- handler:

package Test::TestMod;

use Apache ();
use Apache::Request ();
use CGI ();
use strict;

sub handler {

    my $r = shift;
    my $form = &parseFormApache($r);

    $r->print("Content-type: text/html\n\n");

    $r->print("<table>\n");
    $r->print("<tr><th colspan=2 align=left>ARGS</th></tr>\n");
    foreach my $key (sort keys %$form) {
	my $count = 0;
	$$form{$key} =~ s/\n/'line'.++$count.':'/ge;
	$r->print("<tr><th align=right>$key</th><td><pre>$$form{$key}</pre></td></tr>\n");
    }
    $r->print("</table>\n");

    return 200;

}

sub parseFormApache {

    my ($r) = @_;
    my $apr = Apache::Request->new($r);

    my $form;
    my @params = $apr->param;

    foreach my $param (@params) {
	$$form{$param} = join("\0", $apr->param($param));
    }

    return $form;

}

sub parseFormCGI {

    my ($r) = @_;
    my $cgi = new CGI;

    my $form;
    my @params = $cgi->param;

    foreach my $param (@params) {
	$$form{$param} = join("\0", $cgi->param($param));
    }

    return $form;
}

1;