rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* patch to make deflater do nothing if content-encoding is already set
@ 2009-07-29  3:02 mmb
  0 siblings, 0 replies; only message in thread
From: mmb @ 2009-07-29  3:02 UTC (permalink / raw)
  To: Rack Development


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 <matthewm@boedicker.org>
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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-07-29  3:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-29  3:02 patch to make deflater do nothing if content-encoding is already set mmb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).