http://www.perlmonks.org?node_id=1032881


in reply to Re: Dancer as a proxy
in thread Dancer as a proxy

streaming support depends on the webserver as much as the framework , and a grep http://search.cpan.org/grep?cpanid=YANICK&release=Dancer-1.3113&string=streaming&i=1&n=1&C=3 shows Dancer higher than 1.3072 supports streaming

Streaming data using dancer, Re^3: Resume downloads, Re^2: file download with connection problems, http://search.cpan.org/perldoc/Dancer#send_file

This was really hard to write as the documentation has holes on this, there are no tests on this in test suite, and Dancer hides the errors from these callbacks, so you have to eval { ...; 1 } or warn $@;

get '/stream_example' => sub { return send_file( \'fake contents to be replaced in override', streaming => 1, callbacks => { override => sub { eval { my ( $respond, $response ) = @_; require LWP; my $ua = LWP::UserAgent->new; my $writer ; $ua->get( 'http://www.example.com', ':content_cb' => sub { my ( $data, $response, $protocol ) = @_; if(not $writer ){ my $h = $response->headers ; my $r = [ $response->code, [ map { $_ => $h->{$_}, } 'last-modified' , 'date' , 'content-length' , +'etag' , 'content-type' ], ]; $writer = $respond->( $r ); } $writer->write( $data ); }, ## end of :content_cb ); ## end of $ua->get } or warn "\n\n OH NO\n$@\n\n"; return; }, ## end of override }, ); ## end of send_file }; ## end of get '/stream_example'