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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I've been playing with Dancer for the first time, and I think I found some bugs. I'm posting here to see if this is a ligit bug or if I'm doing something wrong.

I added a file under the public dir of /javascripts/test.js with the text var test = 1;. The Dancer route looks like this:

get '/javascripts/:file' => sub { my ($file) = splat; send_file( '/javascripts/' . params->{file}, streaming => 1, content_type => 'text/javascript', ); };

(There may be better ways to do this, but I'm doing it this way for learning purposes.)

I also wrote tests to handle that:

response_status_is [ GET => '/javascripts/test.js' ], 200, 'response status is 200 for /js/test.js'; response_content_is [ GET => '/javascripts/test.js' ], 'var test = 1;' +, 'Fetched JS'; response_headers_include [ GET => '/javascripts/test.js' ], [ 'Content-Type' => 'text/javascript' ], "MIME type set for JS";

Those fail with:

not ok 4 - Fetched JS # Failed test 'Fetched JS' # at t/002_index_route.t line 14. # got: 'GLOB(0x31fa178)' # expected: 'var test = 1;' not ok 5 - MIME type set for JS # Failed test 'MIME type set for JS' # at t/002_index_route.t line 15. # Looks like you failed 2 tests of 5.

In the debugger, I stepped into reponse_headers_include() and found the response looks like this:

0 Dancer::Response=HASH(0x23dca98) 'content' => GLOB(0x23eb3e8) -> *Dancer::FileUtils::$fh FileHandle({*Dancer::FileUtils::$fh}) => fileno(7) 'encoded' => 0 'forward' => '' 'halted' => 0 'headers' => HTTP::Headers=HASH(0x23e0060) 'content-type' => MIME::Type=HASH(0x1706478) 'MT_encoding' => '8bit' 'MT_extensions' => ARRAY(0x1706580) 0 'js' 'MT_simplified' => 'application/javascript' 'MT_type' => 'application/javascript' 'last-modified' => 'Fri, 01 Mar 2013 15:31:21 GMT' 'pass' => 0 'status' => 200

Notice above that the MIME type override (content_type => 'text/javascript') was not respected as documented in Dancer::send_file(). Also, the response_content_is() is failing because send_file() is returning a filehandle, which I feel should have been automatically expanded rather than failing this way. Removing streaming => 1 does not fix the test. It does return the right data when I check it in a browser.

Also, I originally had a response_exists() test, but the test failed with a deprecation warning. There's no mention of the deprecation in the Dancer::Test docs.

If these are indeed a ligit bug, I already see how to fix the response_content_is problem and can probably figure out the content type override. However, I've been giving Dancer a try for an hour and I'm already running into bugs and documentation errors. Frankly, that's not a good sign of a mature framework.


"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.


In reply to Dancer bugs? send_file(), content type, and response_content_is() by hardburn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (9)
    As of 2014-11-24 14:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (141 votes), past polls