Subject: | CGI::Simple breaks when combining CGI::SpeedyCGI and POST requests |
(copied from a perlmonks post - http://perlmonks.org/?node_id=496230):
I'm running into a little problem with [cpan://CGI::SpeedyCGI|SpeedyCGI] that's stumping me.
In general, I really like Speedy - I switched some [cpan://CGI::Simple] scripts that had severe performance issues to it, and was amazed at the improvement.
The problem is, all those CGIs were just processing GET requests. I'm now trying to write the first one that will accept POSTs, and I can't get it to work.
The code itself is very simple:
<code>
#!/usr/bin/speedy -wT
use strict;
use CGI::Simple;
use MyApp::Theme;
use vars qw/$q/;
$q = new CGI::Simple;
warn $q->Dump;
if ($q->param('theme') =~ m#([\w\-:(){} /]+)#) {
my $theme = $1;
my @themes = map {$_->theme} MyApp::Theme->search_like(theme => $theme."%");
my %matches;
foreach (@themes) {
my $nextslash = index($_, " / ", length $theme);
if ($nextslash == -1) { # not found - it's a leaf
$matches{$_} = $_;
} elsif (not exists $matches{$_}) {
substr($_, $nextslash) = "";
$matches{$_} = "$_ / ";
}
}
print $q->header;
print "<ul>";
foreach (sort keys %matches) {
print "<li>$_</li>";
}
unless (exists $matches{$theme}) {
print "<li>$theme</li>";
}
print "</ul>";
}
</code>
It accepts a single parameter (theme), and returns an unordered list of similar themes (used in an AJAX autocomplete setup). When I run it under normal perl, everything works great:
<code>
$VAR1 = bless( {
'.parameters' => [
'theme',
'_'
],
'.globals' => {
'DEBUG' => '0',
'NO_UNDEF_PARAMS' => '0',
'NO_NULL' => 1,
'FATAL' => -1,
'USE_PARAM_SEMICOLONS' => '0',
'DISABLE_UPLOADS' => 1,
'USE_CGI_PM_DEFAULTS' => '0',
'NPH' => '0',
'POST_MAX' => 102400,
'HEADERS_ONCE' => '0'
},
'.fieldnames' => {
'_' => 1,
'theme' => 1
},
'_' => [
''
],
'theme' => [
'Some value'
]
}, 'CGI::Simple' );
at /var/www/cgi-bin/ac_theme line 16.
</code>
When I switch to speedy, I get this:
<code>
$VAR1 = bless( {
'.globals' => {
'DEBUG' => '0',
'NO_UNDEF_PARAMS' => '0',
'NO_NULL' => 1,
'FATAL' => -1,
'USE_PARAM_SEMICOLONS' => '0',
'DISABLE_UPLOADS' => 1,
'USE_CGI_PM_DEFAULTS' => '0',
'NPH' => '0',
'POST_MAX' => 102400,
'HEADERS_ONCE' => '0'
},
'.cgi_error' => '500 Bad read on POST! wanted 48, got 0'
}, 'CGI::Simple' );
at /var/www/cgi-bin/ac_theme line 16.
</code>
What gives?
<b>Update</b>: Just occured to me to switch to the regular [cpan://CGI], and sure enough, everything works again, even under speedy.
I guess CGI::Simple isn't doing something right?