miyagawa/Plack — Issue #264: P::Handler::CGI odd error on POST if CGI->new() instantiated
Author: osfameron
Created: 2012-01-12 22:39:06+00:00
State: open

While porting part of an app from CGI to Plack, I got an error when attempting to read a POST while using Plack::Handler::CGI:

> Bad Content-Length: maybe client disconnect? (10 bytes remaining)

The error didn't occur a) under ::Handler::FCGI, or b) using GET.

Having investigated further, I've discovered that it's because the legacy library we're using instantiates CGI.
I can workaround by making the instantiation lazy (as the execution path I'm using doesn't actually require it), and the combination of factors that cause the bug is probably just going to happen in my "porting a legacy app" scenario, but thought I should report.

# MINIMAL TEST CASE, 2 files

## cgi-bin/test.cgi

```perl
#!/usr/bin/perl
use Plack::Loader;
my $app = Plack::Util::load_psgi('../psgi/test.psgi');
Plack::Loader->auto->run($app);
```

## psgi/test.psgi

```perl
#!/usr/bin/perl
use strict; use warnings;

use Plack::Request;
use CGI;

sub {
my $env = shift;

my $cgi = CGI->new();

my $req = Plack::Request->new($env);
my $foo = $req->param('foo');

my $body = <

EOF

return [200, ['content-type'=>'text/html'], [$body]];
};
```