From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Status: No, score=-4.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from mail-lf0-f64.google.com (mail-lf0-f64.google.com [209.85.215.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 6ED16203EA for ; Wed, 27 Jul 2016 02:10:53 +0000 (UTC) Received: by mail-lf0-f64.google.com with SMTP id l89sf11292804lfi.1 for ; Tue, 26 Jul 2016 19:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=sender:date:from:to:subject:message-id:mime-version :content-disposition:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=lbFOAJ7KJY9UuJA6D8bO5z6ZzbspJNyRtEyUsEFspJk=; b=J0B6QCsd+FmQn2QypVW1e7CJDG31IG/qz3JXCxpdB7K9rp15MbUbMZYH+W1zFeclwu PGHdRqf+P/oXFtwzcjccCpG9uUFhDCc9tvCP32UM3AxvLw1UsZiG/Niy28HvFQPDn1mt YkKBEJhKbyV1PaNWALQjZyHy1JiGfLOjVh6XW+VS9ysVPh/j9BpIHyO6Qgg9rESVadgW 13nvbcgBng/m0a4y5vUiVU4cpi06p0N6mEkmqVrlTg+x+hbRQQItyfMFHrpqld42DdeQ zHDD0MhzArj2ea9iuEAaRsbDKzef46h1cNNpyhhCQhDUi6FIrAAPZLqX/RG9PidQMdkf codw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=sender:x-gm-message-state:date:from:to:subject:message-id :mime-version:content-disposition:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=lbFOAJ7KJY9UuJA6D8bO5z6ZzbspJNyRtEyUsEFspJk=; b=FfNoPuYlLkqKFVSZ1NkCqhqelnufF+YlJw7nWvpX8Lu5JrPlc/5iKfNpSeV6HX8FOa Q2A3WBouOVhZFqqL/PopMht4eq8A/1SDeYPJIrVm7OEGvTcUINRJsmWUX3+xpG3iQl/p xP7x7hxOfObosEmRfQLC7rl0hgAVh9T8LmVBR6flmyHv85/hzCe8wgBCCTgd/+9pUrwX My2xoeN6QNgAHYE2ic5p8gnSZZUx8Mngl47RU2UkvhE+TqW9DLt1T6/LeXOFd8SS7oip BeWtyTKc9BqhyhM0JLAxcI3M7L9o3v0Ibhbcj57RpsZUTbnFMRBBDOyy3HWB5C6t1Rdl 14Ng== Sender: rack-devel@googlegroups.com X-Gm-Message-State: AEkooustrUnC2WLxOYmMeMz4rpZeDIcYIU5zJmKVP3S76P+vnhBxb6k5a/ZdV8aMZUIwiw== X-Received: by 10.28.29.135 with SMTP id d129mr122111wmd.7.1469585451564; Tue, 26 Jul 2016 19:10:51 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.28.215.5 with SMTP id o5ls943546wmg.2.canary; Tue, 26 Jul 2016 19:10:51 -0700 (PDT) X-Received: by 10.28.203.3 with SMTP id b3mr5901454wmg.1.1469585451121; Tue, 26 Jul 2016 19:10:51 -0700 (PDT) Received: from dcvr.yhbt.net (dcvr.yhbt.net. [64.71.152.64]) by gmr-mx.google.com with ESMTPS id o10si264355wme.0.2016.07.26.19.10.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jul 2016 19:10:51 -0700 (PDT) Received-SPF: pass (google.com: domain of e@80x24.org designates 64.71.152.64 as permitted sender) client-ip=64.71.152.64; Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C2C04203EA; Wed, 27 Jul 2016 02:10:48 +0000 (UTC) Date: Wed, 27 Jul 2016 02:10:48 +0000 From: Eric Wong To: rack-devel@googlegroups.com Subject: [PATCH] deflater: remove "deflate" encoding support Message-ID: <20160727021048.GA27519@starla> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Original-Sender: e@80x24.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of e@80x24.org designates 64.71.152.64 as permitted sender) smtp.mailfrom=e@80x24.org Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: X-Google-Group-Id: 486215384060 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , This will improve cache hit rates and reduce caching overhead at small expense of increased header overhead for some user agents. For reference, Varnish cache supports only gzip as well: https://www.varnish-cache.org/docs/4.1/phk/gzip.html In the past, "deflate" encoding was more likely to trigger user-agent bugs, as noted in the comments removed with this change as well as the Varnish documentation referenced above. --- The following changes since commit 25a549883b85fb33970b4a1530a365c0c9e51f95: bumping to 2.0.1 to work around Rack (2016-06-30 10:33:09 -0700) are available in the git repository at: git://80x24.org/rack.git no-deflate for you to fetch changes up to d6380043a8953dca63743c947c8027f465d29a5d: deflater: remove "deflate" encoding support (2016-07-26 23:14:55 +0000) ---------------------------------------------------------------- Eric Wong (1): deflater: remove "deflate" encoding support lib/rack/deflater.rb | 37 +------------------------------------ test/spec_deflater.rb | 38 ++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 50 deletions(-) diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb index 62a1124..79e39f5 100644 --- a/lib/rack/deflater.rb +++ b/lib/rack/deflater.rb @@ -8,7 +8,6 @@ module Rack # Currently supported compression algorithms: # # * gzip - # * deflate # * identity (no transformation) # # The middleware automatically detects when compression is supported @@ -41,7 +40,7 @@ module Rack request = Request.new(env) - encoding = Utils.select_best_encoding(%w(gzip deflate identity), + encoding = Utils.select_best_encoding(%w(gzip identity), request.accept_encoding) # Set the Vary HTTP header. @@ -57,10 +56,6 @@ module Rack mtime = headers.key?("Last-Modified") ? Time.httpdate(headers["Last-Modified"]) : Time.now [status, headers, GzipStream.new(body, mtime)] - when "deflate" - headers['Content-Encoding'] = "deflate" - headers.delete(CONTENT_LENGTH) - [status, headers, DeflateStream.new(body)] when "identity" [status, headers, body] when nil @@ -101,36 +96,6 @@ module Rack end end - class DeflateStream - DEFLATE_ARGS = [ - Zlib::DEFAULT_COMPRESSION, - # drop the zlib header which causes both Safari and IE to choke - -Zlib::MAX_WBITS, - Zlib::DEF_MEM_LEVEL, - Zlib::DEFAULT_STRATEGY - ] - - def initialize(body) - @body = body - @closed = false - end - - def each - deflator = ::Zlib::Deflate.new(*DEFLATE_ARGS) - @body.each { |part| yield deflator.deflate(part, Zlib::SYNC_FLUSH) } - yield fin = deflator.finish - ensure - deflator.finish unless fin - deflator.close - end - - def close - return if @closed - @closed = true - @body.close if @body.respond_to?(:close) - end - end - private def should_deflate?(env, status, headers, body) diff --git a/test/spec_deflater.rb b/test/spec_deflater.rb index ba7ec5d..0f27c85 100644 --- a/test/spec_deflater.rb +++ b/test/spec_deflater.rb @@ -81,13 +81,22 @@ describe Rack::Deflater do yield(status, headers, body) if block_given? end + # automatic gzip detection (streamable) + def auto_inflater + Zlib::Inflate.new(32 + Zlib::MAX_WBITS) + end + + def deflate_or_gzip + {'deflate, gzip' => 'gzip'} + end + it 'be able to deflate bodies that respond to each' do app_body = Object.new class << app_body; def each; yield('foo'); yield('bar'); end; end - verify(200, 'foobar', 'deflate', { 'app_body' => app_body }) do |status, headers, body| + verify(200, 'foobar', deflate_or_gzip, { 'app_body' => app_body }) do |status, headers, body| headers.must_equal({ - 'Content-Encoding' => 'deflate', + 'Content-Encoding' => 'gzip', 'Vary' => 'Accept-Encoding', 'Content-Type' => 'text/plain' }) @@ -98,15 +107,15 @@ describe Rack::Deflater do app_body = Object.new class << app_body; def each; yield('foo'); yield('bar'); end; end - verify(200, app_body, 'deflate', { 'skip_body_verify' => true }) do |status, headers, body| + verify(200, app_body, deflate_or_gzip, { 'skip_body_verify' => true }) do |status, headers, body| headers.must_equal({ - 'Content-Encoding' => 'deflate', + 'Content-Encoding' => 'gzip', 'Vary' => 'Accept-Encoding', 'Content-Type' => 'text/plain' }) buf = [] - inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS) + inflater = auto_inflater body.each { |part| buf << inflater.inflate(part) } buf << inflater.finish @@ -118,32 +127,33 @@ describe Rack::Deflater do app_body = Object.new class << app_body; def each; yield('foo'); yield('bar'); end; end opts = { 'skip_body_verify' => true } - verify(200, app_body, 'deflate', opts) do |status, headers, body| + verify(200, app_body, 'gzip', opts) do |status, headers, body| headers.must_equal({ - 'Content-Encoding' => 'deflate', + 'Content-Encoding' => 'gzip', 'Vary' => 'Accept-Encoding', 'Content-Type' => 'text/plain' }) buf = [] - inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS) + inflater = auto_inflater FakeDisconnect = Class.new(RuntimeError) assert_raises(FakeDisconnect, "not Zlib::DataError not raised") do body.each do |part| - buf << inflater.inflate(part) + tmp = inflater.inflate(part) + buf << tmp if tmp.bytesize > 0 raise FakeDisconnect end end - assert_raises(Zlib::BufError) { inflater.finish } + inflater.finish buf.must_equal(%w(foo)) end end # TODO: This is really just a special case of the above... it 'be able to deflate String bodies' do - verify(200, 'Hello world!', 'deflate') do |status, headers, body| + verify(200, 'Hello world!', deflate_or_gzip) do |status, headers, body| headers.must_equal({ - 'Content-Encoding' => 'deflate', + 'Content-Encoding' => 'gzip', 'Vary' => 'Accept-Encoding', 'Content-Type' => 'text/plain' }) @@ -280,7 +290,7 @@ describe Rack::Deflater do 'Content-Encoding' => 'identity' } } - verify(200, 'Hello World!', 'deflate', options) + verify(200, 'Hello World!', deflate_or_gzip, options) end it "deflate if content-type matches :include" do @@ -334,7 +344,7 @@ describe Rack::Deflater do :if => lambda { |env, status, headers, body| true } } } - verify(200, 'Hello World!', 'deflate', options) + verify(200, 'Hello World!', deflate_or_gzip, options) end it "not deflate if :if lambda evaluates to false" do -- EW -- --- You received this message because you are subscribed to the Google Groups "Rack Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.