Hi,

I have a (flat) zip-file containing htmls, pngs and jpgs that I want to serve as a website.

I started out with plain psgi, where it was really simple.

Now I want to move to Dancer2 and I seem to have a problem with encodings.

The html-files in the zip are utf-8 and I am using Archive::Zip to read it, so in the psgi-version I did something like

return [200, [ "Content-Type" => "text/html; charset=utf-8"], [ $membe +r->contents ] ];
And that worked.

Now I try to do the same thing in Dancer2 like this:

use strict; use Dancer2; use Archive::Zip; any '/**' => \&handler; sub handler { my($context)=@_; my $zip = Archive::Zip->new; $zip->read("eco.zip") == Archive::Zip::AZ_OK or die "cannot read z +ip\n"; my $path = $context->request->path; $path =~ s|^/||; my $member = $zip->memberNamed($path) or die "no such member: $pat +h\n"; my $type; $type = "text/html; charset=utf-8" if $path =~ /\.html$/; $type = "image/jpg" if $path =~ /\.jpg$/; $type = "image/png" if $path =~ /\.png$/; die "unhandled file: $path\n" unless $type; response_header "Content-Type" => $type; return $member->contents; }; start;
And while it somewhat works (the header seeems to be sent just fine) accented characters look wrong in the browser.

Does anyone have an idea what this could be?

Also I am t a total newbie to Dancer, so I would greatly appreciate any better ways to do this in Dancer as I suppose this is not a very idiomatic way to do this.

Many thanks!


In reply to serving a zip file with Dancer2 by morgon

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.