Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: EOF problem with Dancer streaming proxy

by gsiems (Deacon)
on Jan 12, 2017 at 16:47 UTC ( [id://1179457]=note: print w/replies, xml ) Need Help??


in reply to EOF problem with Dancer streaming proxy

As the author of Dancer as a proxy... I never really did get it working correctly/to my satisfaction for all clients.

For whatever it may be worth-- I've since migrated to Dancer2 and the proxy piece works much better (the code is simpler also).

  • Comment on Re: EOF problem with Dancer streaming proxy

Replies are listed 'Best First'.
Re^2: EOF problem with Dancer streaming proxy
by dsheroh (Monsignor) on Jan 13, 2017 at 12:42 UTC
    If you don't mind sharing, what were some of the (other) problems you ran into with Dancer 1? And what does the corresponding Dancer 2 code look like?

      Streaming in any form was the main problem that I had w/Dancer 1. While moving to Dancer 2 was partially influenced by that, it was also because Dancer 2 has nicer routing and other features.

      The current code looks like:

      sub proxy_request { my $self; $self = shift if ( ( _whoami() )[1] ne (caller)[1] ); my ( $proxy_route, $file_name ) = @_; unless ($proxy_route) { Tranquillus::Util->return_error('BAD_QUERY'); } my $cb = sub { my $respond = $Dancer2::Core::Route::RESPONDER; require LWP; my $ua = LWP::UserAgent->new; my $writer; my %m; $ua->get( $proxy_route, ':content_cb' => sub { my ( $data, $response, $protocol ) = @_; if ( not $writer ) { my $h = $response->headers; my @ary = ( 'Cache-Control', 'Content-Length', 'Content- +Type', 'Last-Modified', 'Content-Disposition' ); foreach my $key (@ary) { if ( $h->header($key) ) { $m{$key} = $h->header($key); } } unless ( exists $m{'Content-Length'} ) { # RFC 7230 # http://tools.ietf.org/html/rfc7230#section-4 $m{'Transfer-Encoding'} = 'chunked'; } if ($file_name) { $m{'Content-Disposition'} ||= 'attachment; fil +ename="' . $file_name . '"'; } $writer = $respond->( [ $response->code, [%m] ] ); } # Ensure that we have a valid writer... if ($writer) { $writer->write($data); } }, ); # Cleanup. # Ensure that we have a valid writer... if ($writer) { if ( exists $m{'Transfer-Encoding'} ) { $writer->write(undef); $writer->write("\r\n"); } $writer->close; } }; my $response = Dancer2::Core::Response::Delayed->new( # error_cb => sub { $weak_self->logger_engine->log( + warning => @_ ) }, cb => $cb, request => $Dancer2::Core::Route::REQUEST, response => $Dancer2::Core::Route::RESPONSE, ); return $response; }

      ... and can be found at: https://github.com/gsiems/tranquillus/blob/master/lib/Tranquillus/Proxy.pm

      Update: fixed the github link.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found