[dancer-users] setting mime type

Puneet Kishor punk.kish at gmail.com
Mon Jul 1 18:53:17 BST 2013


On Jul 1, 2013, at 10:18 AM, Yanick Champoux <yanick at babyl.dyndns.org> wrote:

> On 13-06-30 02:51 AM, Mr. Puneet Kishor wrote:
>> but I need to set the correct mime type for the video. How do I do that with Dancer?
> 
> if you use 'send_file', Dancer will try to guess a decent miem type based on the file's extension.
> 
> If not, you can manipulate the content type via 'response->content_type( 'some/type' )'
> 



I am going to reformulate my question. I have the following code --

In my browser

    <div id="content"></div>

    <script id="tmpl" type="text/x-handlebars-template">
        {{{ text }}}
    </script>

    var tmpl = Handlebars.compile( $("#tmpl").html() );

    $.ajax({
        url	: "/v/" + page,
        type	: "GET",
        dataType: "json",
        error	: function() { alert("Error loading html document"); },
        success : function(res) {
            if (res == null) { return; }
            document.title = res.title;
            $("#content").html( tmpl( {text: res.text} ); );
        }
    });

On my server

    get '/v/:page' => sub {
        my $page = param('page');
        my ($title, $modified_on) = get_page($page);
        debug "sending back $uri";
        my %tmpl_opts = (
            title => $title,
            text  => qq{
                <video width="960" height="540" poster="path/to/movie.jpg" controls preload="auto">
                    <source type="video/mp4" src="path/to/movie.mp4" />
                    <source type="video/ogg" src="path/to/movie.ogv" />
                    <source type="video/webm" src="path/to/movie.webm" />
                    Sorry, your browser has no video playback capabilities
                </video>
            },
            modified_on => $modified_on
        );
	
        return to_json \%tmpl_opts;
    };

The above code works fine on all browsers on the desktop. However, on Safari on iPad the video is disabled. Dancer is running on Starman behind an Apache proxy.

A static test page with the video code (no ajax, no JavaScript templates) served directly by Apache works fine even on Safari on iPad.

What am I doing wrong, and how can I correct this?

--
Puneet Kishor


More information about the dancer-users mailing list