From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.204.72.79 with SMTP id l15cs53799bkj; Tue, 28 Jul 2009 20:15:26 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.140.166.8 as permitted sender) client-ip=10.140.166.8; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.140.166.8 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.140.166.8]) by 10.140.166.8 with SMTP id o8mr4125803rve.17.1248837324307 (num_hops = 1); Tue, 28 Jul 2009 20:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :mime-version:content-type:received:date:x-ip:user-agent :x-http-useragent:message-id:subject:from:to:x-google-approved :reply-to:sender:precedence:x-google-loop:mailing-list:list-id :list-post:list-help:list-unsubscribe:x-beenthere-env:x-beenthere; bh=+JUogKqwA1hzpLUZ5JVqTu7Q6bcX1RHAuB7eAXC0Md4=; b=DIu82kcOxNH8Uob20jOZm1ZkdPwrqHdDu5d4mekk135gQDJLbrsciUs696wIM2GvC2 6iSDVBWSkzD+EG3kpHSbBHiFV7qy0Izwz7N9MqrGmGBAyDWDhuotImdwAwWb4GAOlPK7 RDJCOGfjz4gN+6ozU1Dm334COQAC4Vm3uDATk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:mime-version:content-type:date:x-ip :user-agent:x-http-useragent:message-id:subject:from:to :x-google-approved:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; b=2OckxFqWTey1vNJ3ny6US+S8mq7tvNsFOoOPoJP6l71LgtAr2ai+eU0TiEm60v435I T9u6do+aYYXtGhocXndsdI1uGvM6dJMtmTYyxepacNhT7WQ78S4o+rabV3vht6mTPvYs LtFl/9IeOdWatOBPaKaBeE6WavhPi2aY5inZM= Received: by 10.140.166.8 with SMTP id o8mr728370rve.17.1248837323967; Tue, 28 Jul 2009 20:15:23 -0700 (PDT) Received: by 10.106.63.16 with SMTP id l16gr1531pra.0; Tue, 28 Jul 2009 20:15:12 -0700 (PDT) X-Sender: matthewm@boedicker.org X-Apparently-To: rack-devel@googlegroups.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Received: by 10.100.95.19 with SMTP id s19mr901942anb.24.1248836533585; Tue, 28 Jul 2009 20:02:13 -0700 (PDT) Date: Tue, 28 Jul 2009 20:02:13 -0700 (PDT) X-IP: 74.79.51.177 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.196.0 Safari/532.0,gzip(gfe),gzip(gfe) Message-ID: <7c896db0-29f1-455c-8b44-eda58ca33b1c@r27g2000vbn.googlegroups.com> Subject: patch to make deflater do nothing if content-encoding is already set From: mmb To: Rack Development X-Google-Approved: james.britt@gmail.com via email at 2009-07-29 03:15:12 Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com This will handle content encoding being set by another middleware or "use Rack::Deflater" being called twice. >From b186a5a3497fe9003a431394958ef3d87786a5c1 Mon Sep 17 00:00:00 2001 From: Matthew M. Boedicker Date: Tue, 28 Jul 2009 22:41:37 -0400 Subject: [PATCH] leave content encoding and content as is when there is already a content encoding --- lib/rack/deflater.rb | 3 ++- test/spec_rack_deflater.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb index 14137a9..109df06 100644 --- a/lib/rack/deflater.rb +++ b/lib/rack/deflater.rb @@ -16,7 +16,8 @@ module Rack # Skip compressing empty entity body responses and responses with # no-transform set. if Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) || - headers['Cache-Control'].to_s =~ /\bno-transform\b/ + headers['Cache-Control'].to_s =~ /\bno-transform\b/ || + headers['Content-Encoding'] return [status, headers, body] end diff --git a/test/spec_rack_deflater.rb b/test/spec_rack_deflater.rb index c9bb318..dd63769 100644 --- a/test/spec_rack_deflater.rb +++ b/test/spec_rack_deflater.rb @@ -124,4 +124,14 @@ context "Rack::Deflater" do response[1].should.not.include "Content-Encoding" response[2].join.should.equal("Hello World!") end + + specify "should leave content and encoding as is when there is already a content-encoding" do + app = lambda { |env| [200, {'Content-Encoding' => 'something'}, ['Hello World!']] } + request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip") + response = Rack::Deflater.new(app).call(request) + + response[1].should.include("Content-Encoding") + response[1]['Content-Encoding'].should.equal("something") + response[2].join.should.equal("Hello World!") + end end -- 1.6.0.4