Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Write a Filehandle w/Dancer2

by hardburn (Abbot)
on Aug 14, 2014 at 01:04 UTC ( #1097367=note: print w/replies, xml ) Need Help??


in reply to Write a Filehandle w/Dancer2

Annnnndddddd . . . it's not actually implemented in Dancer2 yet. Stepping through with the debugger, into Dancer2::Core::App::send_file() finds:

571==> ( ref($path) eq 'SCALAR' ) 572 and return $$path;

Which explains why it just returns when a scalarref is passed. There's also nowhere in the code that actually handles the callback. Plus, there's a comment at the end of:

595 # TODO Streaming support

So, that's that, then.


"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^2: Write a Filehandle w/Dancer2
by Anonymous Monk on Aug 14, 2014 at 01:16 UTC

    Hi, I just saw that to in Dancer2::Core::App

    There's also nowhere in the code that actually handles the callback.

    Sure there is, send_file creates a Dancer2::Handler::File , which does that

    Regarding streaming the https://metacpan.org/pod/Dancer2::Manual#send_file says Send file supports streaming possibility using PSGI streaming. The server should support it but normal streaming is supported on most, if not all.

    So , give it real pathname (not a scalar reference), and try override

      Tried this, but it gives a 404 error:

      return send_file( '/dev/null', streaming => 1, system_path => 1, content_type => $mime_type, callbacks => { override => sub { my ($respond, $response) = @_; my $writer = $respond->([ 200, {} ]); my $buf = ''; while( read( $in_fh, $buf, VID_READ_LENGTH ) ) { $writer->write( $buf ); } } }, );

      Debugger still shows that the callback isn't called.


      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

        I do believe that the docs for Dancer2 send_file are more "wishlist" or "todo" than "this is how it works", this is based of my reading of send_file and Dancer2::Handler::File

        send the bug upstream :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2019-09-16 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (196 votes). Check out past polls.

    Notices?