CGI.pm POST test
hi all
attached is a test that uses CGI.pm to parse large chunks of POST data.
currently, it fails for me in tests 3-6, which corresponds to a recent
discussion on modperl@ where a user was seeing only part of his POST data
for largish chunks.
granted, after discussing with stas, the problem isn't really due to CGI.pm,
so the test is excercising mod_perl internals rather than CGI.pm. however,
the test is probably similar to one a user would have sent, and it we had
had the test we wouldn't have gotten the bug report :) and, since we have
redirect and cookie tests in the Registry suite, it can't hurt to have this
one as well - more tests == good software :)
I don't want to commit it, though, until the underlying problem is fixed, so
it's really just FYI at this point.
--Geoff
--- /dev/null 2003-01-30 05:24:37.0 -0500
+++ ModPerl-Registry/t/cgi-post.t 2003-10-31 14:27:43.0 -0500
@@ -0,0 +1,31 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestRequest qw(POST_BODY);
+
+plan tests => 6, have_min_module_version(CGI => 2.93);
+
+foreach my $post (25, 50, 75, 100, 125, 150) {
+my %param = ();
+
+foreach my $key (1 .. $post) {
+ $param{$key} = 'data' x $key;
+}
+
+my $post_data = join '&', map { "$_=$param{$_}" }
+ sort { $a <=> $b } keys %param;
+my $expected = join ':', map { $param{$_} }
+ sort { $a <=> $b } keys %param;
+
+my $e_length = length $expected;
+
+my $url = "/registry/cgi-post.pl";
+
+my $received = POST_BODY $url, content => $post_data;
+
+my $r_length = length $received;
+
+print STDERR "excpected $e_length bytes, received $r_length bytes\n";
+ok ($expected eq $received);
+}
--- /dev/null 2003-01-30 05:24:37.0 -0500
+++ ModPerl-Registry/t/cgi-bin/cgi-post.pl 2003-10-31 14:03:43.0 -0500
@@ -0,0 +1,10 @@
+use strict;
+use warnings FATAL => 'all';
+
+use CGI;
+
+my $q = CGI->new;
+
+print "Content-Type: text/plain\n\n";
+
+print join ":", map { $q->param($_) } $q->param;
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
[mp2] print efficiency
You learn a lot from looking at the low-level tracing. While looking at some
problems with IO. I've traced the modules/cgiupload test and observed that it
does too many read/write calls on a big file. So I've changed it to slurp the
file at once and print it out in one go. While there were just a few read
calls, to my surprise it still did many write calls as if it was printed line
by line. Only after adding 'local $/' everything went in one write call. I
wonder if it's a bug in PerlIO.
Index: t/response/TestModules/cgiupload.pm
===
RCS file: /home/cvs/modperl-2.0/t/response/TestModules/cgiupload.pm,v
retrieving revision 1.2
diff -u -r1.2 cgiupload.pm
--- t/response/TestModules/cgiupload.pm 11 Apr 2002 11:08:45 - 1.2
+++ t/response/TestModules/cgiupload.pm 31 Oct 2003 21:00:06 -
@@ -13,11 +13,10 @@
my $cgi = CGI->new;
+local $\;
+local $/;
my $file = $cgi->param('filename');
-
-while (<$file>) {
-print;
-}
+print <$file>;
Apache::OK;
}
__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI.pm POST test
Geoffrey Young wrote:
hi all
attached is a test that uses CGI.pm to parse large chunks of POST data.
currently, it fails for me in tests 3-6, which corresponds to a recent
discussion on modperl@ where a user was seeing only part of his POST
data for largish chunks.
granted, after discussing with stas, the problem isn't really due to
CGI.pm, so the test is excercising mod_perl internals rather than
CGI.pm. however, the test is probably similar to one a user would have
sent, and it we had had the test we wouldn't have gotten the bug report
:) and, since we have redirect and cookie tests in the Registry suite,
it can't hurt to have this one as well - more tests == good software :)
I don't want to commit it, though, until the underlying problem is
fixed, so it's really just FYI at this point.
Thanks Geoff! This test is indeed was missing, since cgiupload tested
multipart POST, but not a plain POST. Now if you don't mind I've moved your
proposed test to where all the CGI.pm tests are. There really no need to run
it off registry.
Also I've s/BODY/BODY_ASSERT/ since if something fails it'll return an error
response body, which is normally OK if you compare the string, but since the
debug line was printing the length of the response it was misleading. Also
changed s/print STDERR/t_debug/ which does it consistently with other debug
prints (starting with leading # ). Finally removed the hardcoded number of tests.
I've posted a patch to CGI.pm that makes this test pass.
--- /dev/null 1969-12-31 16:00:00.0 -0800
+++ t/modules/cgipost.t 2003-10-31 13:26:22.0 -0800
@@ -0,0 +1,36 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::TestRequest qw(POST_BODY_ASSERT);
+
+my $module = 'TestModules::cgipost';
+my $url = '/' . Apache::TestRequest::module2path($module);
+
+my @data = (25, 50, 75, 100, 125, 150);
+
+plan tests => scalar(@data), have_min_module_version(CGI => 2.93);
+
+foreach my $post (@data) {
+my %param = ();
+
+foreach my $key (1 .. $post) {
+ $param{$key} = 'data' x $key;
+}
+
+my $post_data = join '&', map { "$_=$param{$_}" }
+ sort { $a <=> $b } keys %param;
+my $expected = join ':', map { $param{$_} }
+ sort { $a <=> $b } keys %param;
+
+my $e_length = length $expected;
+
+my $received = POST_BODY_ASSERT $url, content => $post_data;
+
+my $r_length = length $received;
+
+t_debug "expected $e_length bytes, received $r_length bytes\n";
+ok ($expected eq $received);
+}
+
--- /dev/null 1969-12-31 16:00:00.0 -0800
+++ t/response/TestModules/cgipost.pm 2003-10-31 13:25:51.0 -0800
@@ -0,0 +1,25 @@
+package TestModules::cgipost;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::compat ();
+use CGI ();
+
+use Apache::Const -compile => 'OK';
+
+sub handler {
+my $r = shift;
+
+$r->content_type('text/plain');
+my $cgi = CGI->new;
+
+print join ":", map { $cgi->param($_) } $cgi->param;
+
+Apache::OK;
+}
+
+1;
+__END__
+SetHandler perl-script
+PerlOptions +GlobalRequest
__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI.pm POST test
Thanks Geoff! This test is indeed was missing, since cgiupload tested multipart POST, but not a plain POST. Now if you don't mind I've moved your proposed test to where all the CGI.pm tests are. There really no need to run it off registry. fine. Also I've s/BODY/BODY_ASSERT/ since if something fails it'll return an error response body, which is normally OK if you compare the string, but since the debug line was printing the length of the response it was misleading. ok Also changed s/print STDERR/t_debug/ which does it consistently with other debug prints (starting with leading # ). I could have sworn that t_debug printed headers and content, which I specifically didn't want. but from looking at the code, it doesn't. so ok. Finally removed the hardcoded number of tests. fine. I've posted a patch to CGI.pm that makes this test pass. excellent. commit at will, then. --Geoff - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
