Giter VIP home page Giter VIP logo

plack-middleware-deflater's Issues

Is change of version 0.10 correct ?

Test of Furl's t/100_low/13_deflate.t is passed with Plack::Middleware::[email protected], but it is failed with Plack::Middleware::[email protected].

% cpanm -q Plack::Middleware::[email protected]
Successfully installed Plack-Middleware-Deflater-0.09 (downgraded from 0.10)
1 distribution installed
% prove -b t/100_low/13_deflate.t                                    
t/100_low/13_deflate.t .. ok     
All tests successful.
Files=1, Tests=240,  1 wallclock secs ( 0.05 usr  0.00 sys +  0.97 cusr  0.09 csys =  1.11 CPU)
Result: PASS


% cpanm -q Plack::Middleware::[email protected]
Successfully installed Plack-Middleware-Deflater-0.10 (upgraded from 0.09)
1 distribution installed
% prove -b t/100_low/13_deflate.t
t/100_low/13_deflate.t .. 1/? Uncompress error: data error at /home/syohei/.cpanm/work/1375777569.30022/Furl-2.17/blib/lib/Furl/HTTP.pm line 760.
# Tests were run but no plan was declared and done_testing() was not seen.
t/100_low/13_deflate.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
All 1 subtests passed 

Test Summary Report
-------------------
t/100_low/13_deflate.t (Wstat: 65280 Tests: 1 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output
Files=1, Tests=1,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.10 cusr  0.01 csys
 =  0.13 CPU)
Result: FAIL

Another example.

# app.psgi
use strict;
use warnings;
use Plack::Builder;

my $app = sub {
    return [200, [], ["Hello World"]];
};

builder {
    enable "Deflater";
    $app;
};
% curl --compressed http://localhost:5000 # plackup app.psgi with Version 0.09
Hello World
% curl --compressed http://localhost:5000 # plackup app.psgi with Version 0.10
curl: (61) Error while processing content unencoding: invalid block type

conditionally enable deflater based on response content type is hard

because we have to wait for the underlying response to determine content_type.

right now you have to do:
enable 'Deflater';
enable sub { my $app = shift;
sub { my $env = shift;
my $res = $app->($env);
# skip streamy response
return $res unless ref($res) eq 'ARRAY' && $res->[2];
my $h = Plack::Util::headers($res->[1]);
my $type = $h->get('Content-Type')
or return $res;
delete $env->{HTTP_ACCEPT_ENCODING}
unless $type =~ m|application/x-javascript| || $type =~ m|^text/|;
$res }
};

but this doesn't disable the middleware completely, the side-effect is that deflater still removes the content-length header and adds vary header for your image/png responses, which is probably not cache-friendly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.