【问题标题】:Why does "HTML::Mason::PSGIHandler" not work with 'Plack::Middleware::Debug::Parameters'?为什么“HTML::Mason::PSGIHandler”不能与“Plack::Middleware::Debug::Parameters”一起使用?
【发布时间】:2015-08-28 11:30:50
【问题描述】:

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

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

是什么导致了这个问题?

【问题讨论】:

    标签: handler mason plack psgi


    【解决方案1】:

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

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

    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->{'psgi.input'} 将 STDIN 替换为 Stream::Buffered。所以CGI的$self-&gt;read_from_client(...)没有注意到变化:

    参见PSGI::CGI

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 2014-11-26
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多