1nickt has asked for the wisdom of the Perl Monks concerning the following question:

Update: If you submit your POST request to Dancer using Angular's $resource controller, and you try to return either a redirect() or a send_file() response, Angular will hijack it and it will never be returned to the client. Nothing at all is returned to the browser, and nothing is printed to the log, because Dancer thinks the response was sent out, and even the browser sees a 200 HTTP response code. But somehow Angular holds on to the response and doesn't display it.

I solved the issue in my case by creating a standard HTTP POST form.

Update: I titled my post wrongly, changed to reflect that the issue is with POST requests. Sorry for the confusion.

Hi all,

Is there a restriction in the use of Dancer's send_file() with in-memory filehandles that limits its use to GET requests? My experimentation indicates so, but the docs don't mention it.

Update: Here is a short example:

This code results in the browser downloading a CSV file:

get '/test/csv' => sub { my $csv = "foo, bar, baz"; send_file( \$csv, content_type => 'text/csv', filename => 'qux.csv +' ); };
While this produces nothing returned to the browser and nothing in the error log:
post '/test/csv' => sub { my $csv = "foo, bar, baz"; send_file( \$csv, content_type => 'text/csv', filename => 'qux.csv +' ); };

Update: Tried using return redirect '/get_resource'; in the POST handler but even so there is nothing output to the log or the browser.

Thanks!

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: Dancer::send_file only for POST?
by Corion (Patriarch) on Nov 11, 2015 at 13:38 UTC

    Even the Dancer documentation shows as an example a GET request/handler for send_file, so I would assume that it works. But the documentation also lists some prerequisites like the file living below the public directory etc.

    Maybe you can show us a small example of how send_file fails for you?

      Sorry, too early! Updated my question which is about in-memory "files" only.
      The way forward always starts with a minimal test.

        I'm sorry to be so snarky, but as I've already asked you to provide more detail, I'll quote your signature here:

        The way forward always starts with a minimal test.

        Please, do provide us with a minimal example that we can use to reproduce your case. Also tell us what PSGI webserver you're using. Different webservers have different features and maybe the webserver your're using tries to be smart about sending files by delegating this task to the operating system by name.

        Some of the tests seem to allow send_file( \$data, ... ), so maybe you're not filling $data properly in the GET case? A short example should help us help you better here.

Re: Dancer::send_file only for GET? (and POST)
by Anonymous Monk on Nov 12, 2015 at 03:39 UTC
    It works for both get and post
    $ lwp-request -m get http://localhost:3000/test/wee/csv wee,get,this $ lwp-request -m post http://localhost:3000/test/wee/csv Please enter content (application/x-www-form-urlencoded) to be POSTed: done ^Z wee,post,this $ mversion Dancer 1.3135
    thats from 2015-04-22

    It also works on 1.3202 2015-11-07