From 1823c04db881f302c01b042a3718fc49c3174d29 Mon Sep 17 00:00:00 2001 From: Michael Jemmeson Date: Fri, 13 May 2011 10:18:30 +0100 Subject: [PATCH] no compression on x-reproxy-url responses --- lib/Plack/Middleware/Deflater.pm | 4 ++++ t/headers.t | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) mode change 100644 => 100755 lib/Plack/Middleware/Deflater.pm create mode 100755 t/headers.t diff --git a/lib/Plack/Middleware/Deflater.pm b/lib/Plack/Middleware/Deflater.pm old mode 100644 new mode 100755 index bf9eaee..3b2725f --- a/lib/Plack/Middleware/Deflater.pm +++ b/lib/Plack/Middleware/Deflater.pm @@ -32,6 +32,10 @@ sub call { return if $env->{HTTP_CONTENT_RANGE}; my $h = Plack::Util::headers($res->[1]); + + # do not compress Perlbal reproxy URLs + return if $h->get('X-REPROXY-URL'); + my $content_type = $h->get('Content-Type') || ''; $content_type =~ s/(;.*)$//; if ( my $match_cts = $self->content_type ) { diff --git a/t/headers.t b/t/headers.t new file mode 100755 index 0000000..1581ce5 --- /dev/null +++ b/t/headers.t @@ -0,0 +1,36 @@ +use strict; +use Test::More; +#use Test::Requires qw(IO::Handle::Util); +#use IO::Handle::Util qw(:io_from); +use HTTP::Request::Common; +use Plack::Builder; +use Plack::Test; +use Plack::Middleware::Deflater; +$Plack::Test::Impl = "Server"; + +# no compression on X-REPROXY-URL +my $app = builder { + enable 'Deflater', content_type => 'text/html', vary_user_agent => 1; + sub { + [ 200, + [ 'Content-Length' => '100', + 'Content-type' => 'text/plain', + 'X-REPROXY-URL' => + 'http://10.0.0.1:7500/dev1/0/000/000/0000000001.fid', + ], + ['http://10.0.0.1:7500/dev1/0/000/000/0000000001.fid'], + ]; + } +}; + +test_psgi + app => $app, + client => sub { + my $cb = shift; + my $req = HTTP::Request->new( GET => "http://localhost/" ); + my $res = $cb->($req); + isnt $res->content_encoding, 'gzip', 'no content-encoding'; + }; + +done_testing; +