为什么" HTML :: Mason :: PSGIHandler"不能使用普拉克::中间件::调试::参数'?

时间:2015-08-28 11:30:51

标签: handler mason plack psgi

一切正常,直到你发布值并获得:

[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.

该应用程序的骨架是:

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;
}

导致此问题的原因是什么?

1 个答案:

答案 0 :(得分:0)

这意味着您的CGI :: PSGI在Plack :: Request(由Plack :: Middleware :: Debug :: Parameters使用)之前读取STDIN。

要在您的应用程序中解决此问题,您必须致电:

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;
}

发生了什么事?

Plack::Request读取正文并将其恢复至$ env-&gt; {&#39; psgi.input&#39;}将STDIN替换为{{1} }}。所以CGI的Stream::Buffered没有注意到变化:

参见 PSGI :: CGI

$self->read_from_client(...)