in reply to Re^2: How to use Plack::Middleware::Static
in thread How to use Plack::Middleware::Static

Per default, Plack::Middleware::Static will serve your files depending on their extension by using Plack::MIME. So I suggest that you just drop your own invocation of Plack::MIME for the "normal" behaviour and override it for your download directory like this: content_type => sub { 'text/plain' }

Edited to add: After a glance at the code, you can also provide the content type directly:

content_type => 'text/plain'

Replies are listed 'Best First'.
Re^4: How to use Plack::Middleware::Static
by vhein79 (Novice) on Mar 04, 2021 at 08:21 UTC
    Thank you very much! That does what I want and is clear to me:
    use Plack::Builder; use Plack::MIME; my $expr = qr{\.c|\.cpp|\.csv|\.dat|\.dpl|\.gp|\.h|\.hpp|\.html| \.ini|\.java|\.js|makefile|\.m|\.mac| \.pl|\.pm|\.pod|\.py|readme|\.sch|\.sh|\.txt}xi; builder { # normal behaviour outside of downloads enable 'Plack::Middleware::Static', path => qr{^/html/(?!downloads/)}, root => '.'; # plain text for non binary download files enable 'Plack::Middleware::Static', path => qr{^/html/downloads/.*($expr)$}, root => '.', content_type => 'text/plain'; # download only for the other download files enable 'Plack::Middleware::Static', path => qr{^/html/downloads/.*(?!$expr)$}, root => '.', content_type => 'mime/type'; mount "/" => $app1; mount "/imggenerator.pl" => $app2; };