summary refs log tree commit
diff options
context:
space:
mode:
authorFelix Bùˆnemann <buenemann@louis.info>2019-09-09 19:57:51 +0200
committerFelix Bùˆnemann <buenemann@louis.info>2019-09-10 14:50:12 +0200
commitc41979d978d24b03ed0186e052bc9c6a8ec7ff96 (patch)
treea365c8514f3d0547e065c5a31e17635509fb4b87
parent9fbff6e305ad398ed43e70d7c80f4fdd5e7774e4 (diff)
downloadrack-c41979d978d24b03ed0186e052bc9c6a8ec7ff96.tar.gz
Fix handling of empty body parts in Rack::Deflater
This avoids flushing the Zlib writer, if the length of the written part
is zero to avoid Zlib::BufError exceptions.
-rw-r--r--lib/rack/deflater.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb
index ce248c66..939832ce 100644
--- a/lib/rack/deflater.rb
+++ b/lib/rack/deflater.rb
@@ -88,8 +88,9 @@ module Rack
         gzip = ::Zlib::GzipWriter.new(self)
         gzip.mtime = @mtime if @mtime
         @body.each { |part|
-          gzip.write(part)
-          gzip.flush if @sync
+          len = gzip.write(part)
+          # Flushing empty parts would raise Zlib::BufError.
+          gzip.flush if @sync && len > 0
         }
       ensure
         gzip.close