morgon has asked for the wisdom of the Perl Monks concerning the following question:
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
And that worked.return [200, [ "Content-Type" => "text/html; charset=utf-8"], [ $membe +r->contents ] ];
Now I try to do the same thing in Dancer2 like this:
And while it somewhat works (the header seeems to be sent just fine) accented characters look wrong in the browser.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;
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: serving a zip file with Dancer2
by 1nickt (Canon) on May 14, 2018 at 14:27 UTC | |
by morgon (Priest) on May 14, 2018 at 14:33 UTC | |
Re: serving a zip file with Dancer2
by morgon (Priest) on May 14, 2018 at 15:05 UTC | |
Re: serving a zip file with Dancer2
by Anonymous Monk on May 14, 2018 at 17:37 UTC | |
by Your Mother (Archbishop) on May 14, 2018 at 17:51 UTC | |
by morgon (Priest) on May 14, 2018 at 17:44 UTC |
Back to
Seekers of Perl Wisdom