如何从Dancer Route保持HTTP连接

时间:2013-04-02 01:18:27

标签: html5 perl http dancer

我在项目中使用Perl Dancer,我想实施SSE http://www.html5rocks.com/en/tutorials/eventsource/basics/#toc-introduction-differences

我有一条舞者路线,我正试图保持活力

get '/stream' => sub{
    my $response = Dancer::SharedData->response;
    debug($response->exists);
    $response->status(200);
    $response->content("data: cool test\n\n");
    $response->content_type( 'text/event-stream' );
    $response->header( 'Cache-Control' => 'no-cache' );
    $response->header( 'Connection' => 'Keep-Alive' );
    $response->pass;
    return undef;
};

似乎从舞者路线返回任何内容会关闭连接。理想情况下,我希望将其保持打开并存储$response以便将更多数据推送到以后。

更新:关于进一步的研究,看起来应该可以使用舞者使用的PSGI: http://search.cpan.org/~miyagawa/PSGI-1.03/PSGI.pod#Delayed_Reponse_and_Streaming_Body 目前正在研究中间件方法。

1 个答案:

答案 0 :(得分:0)

这里的答案是转移到另一个网络服务器。我正在使用不支持http连接的starman。转向mojolicious或twiggy。

相关问题