rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: mmb <matthewm@boedicker.org>
To: Rack Development <rack-devel@googlegroups.com>
Subject: patch to make deflater do nothing if content-encoding is already set
Date: Tue, 28 Jul 2009 20:02:13 -0700 (PDT)	[thread overview]
Message-ID: <7c896db0-29f1-455c-8b44-eda58ca33b1c@r27g2000vbn.googlegroups.com> (raw)


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

                 reply	other threads:[~2009-07-29  3:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c896db0-29f1-455c-8b44-eda58ca33b1c@r27g2000vbn.googlegroups.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).