0

Everything is OK, until you post values and get:

[uwsgi-perl error] Bad Content-Length: maybe client disconnect? (45 bytes remaining) at /home/user/perl5/lib/perl5/Plack/Middleware/Debug/Parameters.pm line 20.

The skeleton of the application is:

use Modern::Perl;
use HTML::Mason::PSGIHandler;

$app = sub {
    my $env = shift;

    $h = HTML::Mason::PSGIHandler->new(%mason_config);
    $h->handle_psgi($env);
}

use Plack::Builder;
my $b = builder {
    enable "Debug", panels => ['Parameters'];
    $app;
}

What causes this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158

1 Answers1

0

This means your CGI::PSGI reads STDIN before Plack::Request (which is used by Plack::Middleware::Debug::Parameters).

To workaround this in your application, you must call:

Plack::Request->new($env)->body_parameters;

use Modern::Perl;
use HTML::Mason::PSGIHandler;

$app = sub {
    my $env = shift;

    $h = HTML::Mason::PSGIHandler->new(%mason_config);

    Plack::Request->new($env)->body_parameters; #<<<WORKAROUND
    $h->handle_psgi($env);
}

use Plack::Builder;
my $b = builder {
    enable "Debug", panels => ['Parameters'];
    $app;
}

What is coming on?

Plack::Request will read body and put it back to $env->{'psgi.input'} replacing STDIN by Stream::Buffered. So CGI's$self->read_from_client(...) does not notice changes:

See PSGI::CGI

sub read_from_client {

    my($self, $buff, $len, $offset) = @_;
    my $read = $self->{psgi_env}{'psgi.input'}->read($$buff, $len, $offset);

    return $read;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158