diff options
author | Eric Wong <e@80x24.org> | 2017-06-29 01:59:51 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-06-29 02:04:41 +0000 |
commit | 181e56e011f4c321895bfd01f20cccb3ec1cafa5 (patch) | |
tree | ee364be9f4f5fea9787fd0e186c537d68f8a0d85 /test/spec_deflater.rb | |
parent | 1b94e07f8600dd65a8ba1970161e97e32690e05c (diff) | |
download | rack-181e56e011f4c321895bfd01f20cccb3ec1cafa5.tar.gz |
deflater: support "sync: false" option
Flushing after after very flush is great for real-time apps.
However, flushing is inefficient when apps use Rack::Response
to generate many small writes (e.g. Rack::Lobster).
Allow users to disable the default "sync: true" behavior to
reduce bandwidth usage, otherwise using Rack::Deflater can lead
to using more bandwidth than without it.
Diffstat (limited to 'test/spec_deflater.rb')
-rw-r--r-- | test/spec_deflater.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/spec_deflater.rb b/test/spec_deflater.rb index 0f27c859..410a1438 100644 --- a/test/spec_deflater.rb +++ b/test/spec_deflater.rb @@ -372,4 +372,38 @@ describe Rack::Deflater do verify(200, response, 'gzip', options) end + + it 'will honor sync: false to avoid unnecessary flushing' do + app_body = Object.new + class << app_body + def each + (0..20).each { |i| yield "hello\n".freeze } + end + end + + options = { + 'deflater_options' => { :sync => false }, + 'app_body' => app_body, + 'skip_body_verify' => true, + } + verify(200, app_body, deflate_or_gzip, options) do |status, headers, body| + headers.must_equal({ + 'Content-Encoding' => 'gzip', + 'Vary' => 'Accept-Encoding', + 'Content-Type' => 'text/plain' + }) + + buf = '' + raw_bytes = 0 + inflater = auto_inflater + body.each do |part| + raw_bytes += part.bytesize + buf << inflater.inflate(part) + end + buf << inflater.finish + expect = "hello\n" * 21 + buf.must_equal expect + raw_bytes.must_be(:<, expect.bytesize) + end + end end |