Skip Menu |

This queue is for tickets about the CGI-Simple CPAN distribution.

Report information
The Basics
Id: 14838
Status: resolved
Priority: 0/
Queue: CGI-Simple

People
Owner: Nobody in particular
Requestors: perl [...] peeron.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.077
Fixed in: (no value)



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?
Subject: PATCH: CGI::Simple fails to post HTTP::Request::Common post
From: markstos [...] cpan.org
Here's a test script which illustrates input that CGI::Simple can't handle, but CGI.pm can: http://mark.stosberg.com/perl/cgi-simple-bad-post.pl You'll have to provide your own dummy 't/test_file.txt' file to go with it (contents don't matter, but have to exist). You can easily modify the test to use CGI.pm instead and observe that it works. The test may look contrived, but this pattern is how I'm testing file uploads for CGI::Uploader and it works very well (with CGI.pm!). See also: http://use.perl.org/~markjugg/journal/28038 Mark
Thanks for that Mark. CGI::Simple doesn't like multipart requests that don't specify the boundary in the Content-type. The attached is an amended version of your test that passes with CGI::Simple. I'm toying with adding a heuristic to handle the case where the boundary isn't specified. But for now I'm going to declare it expected behavior :)
use strict; use warnings; use Test::More; Test::More->builder->no_ending(1); use Config; use CGI::Simple; $| = 1; BEGIN { if ( !$Config{d_fork} ) { plan skip_all => "fork not available on this platform"; } eval "use HTTP::Request::Common"; plan skip_all => "HTTP::Request::Common not available" if $@; plan tests => 1; } my $req = HTTP::Request::Common::POST( '/dummy_location', Content_Type => 'form-data', Content => [ test_file => ["t/90.14838.t"], ] ); # Useful in simulating an upload. $ENV{REQUEST_METHOD} = 'POST'; $ENV{CONTENT_TYPE} = $req->header('Content-type'); $ENV{CONTENT_LENGTH} = $req->content_length; if ( open( CHILD, "|-" ) ) { print CHILD $req->content; close CHILD; exit 0; } $CGI::Simple::DISABLE_UPLOADS = 0; my $q = new CGI::Simple; is $q->cgi_error, undef, "CGI::Simple can handle this";
Hi Andy This problem has become painful. It looks like Firefox V 3 usually does not send a boundary, so uploads virtually never work, but just end without error, with the data vanishing. I implore you to unresolve this, and figure out a patch. TIA.
I've added a heuristic (r4450) to handle the case where no explicit boundary is provided. Thanks :)