Rendering Binary Data

50 views
Skip to first unread message

Martin Onegu

unread,
Sep 2, 2015, 5:30:43 AM9/2/15
to Mojolicious
Hey there,

i've got some binary data (in fact it is a pcap file content) in my $res scalar and within my controller i do the following let this content be downloaded by the browswer.


    $self->res->headers->content_type('application/x-download');
    $self->res->headers->content_disposition("attachment; filename=$id.bin;");
    return $self->render(data => $res);


Whats going wrong is that the binary that i download with (different) browsers is different than the original data, the md5_hex($res) is different then md5sum on my file on console.

When looking closer on the content, downloaded and original data, i see that there are some bytes in the beginning that differ (though they have the same size, which is extra confusing)

/tmp % head -n 2 download.hex result.hex
==> download.hex <==
0000000: c394 c383 c2b2 c2a1 0200 0400 0000 0000  ................
0000010: 0000 0000 c3bf c3bf 0000 0100 0000 68c2  ..............h.

==> result.hex <==
0000000: d4c3 b2a1 0200 0400 0000 0000 0000 0000  ................
0000010: ffff 0000 0100 0000 6889 dd55 b7da 0100  ........h..U....


% ls -l 290028E2-50B7-11E5-9379-5C5CF516A027.bin
-rw-r----- 1 martin martin 1519484 Sep  2 11:04 290028E2-50B7-11E5-9379-5C5CF516A027.bin

ls -l result 
-rw-r----- 1 martin martin 1519484 Sep  2 11:07 result


Can you point out what i am doing wrong?

Martin Onegu

unread,
Sep 2, 2015, 9:23:49 AM9/2/15
to Mojolicious
Hello,

i was able to figure out that this bug actually is only in combination with the morbo webserver.

If I am using something else => everything works as ecpected.
If I am using morbo like that:

$PERL -I ../lib -I "${BASEDIR}/lib" $MORBO \
    -l "https://*:${DEFAULT_PORT}?cert=/...../server.crt&key=/........./server.pem" \
    $DEFAULT_SCRIPT

Its broken!!

If i am using morbo like that:
$PERL -I ../lib -I "${BASEDIR}/lib" $MORBO \
     -l "http://*:${DEFAULT_PORT}" \
$DEFAULT_SCRIPT

its working fine as well!

sri

unread,
Sep 2, 2015, 10:23:46 AM9/2/15
to Mojolicious
    return $self->render(data => $res);


This should work, Mojolicious does not modify the value.

--
sebastian 
Reply all
Reply to author
Forward
0 new messages