|
it "dechunks the body when a chunked response is detected", |
|
:lib => [:rails23, :rails31, :rails32, :rails40] do |
|
require 'rack/chunked' |
|
|
|
headers = { |
|
"Cache-Control" => 'no-cache', |
|
"Transfer-Encoding" => 'chunked' |
|
} |
|
body = [ |
|
"1".freeze, |
|
"\nsecond chunk", |
|
"a multi\nline chunk \n42", |
|
"utf-8 chunk 'ty píčo'!\n", |
|
"terminated chunk\r\n", |
|
"", # should be skipped |
|
"\r\nthe very\r\n last\r\n\r\n chunk" |
|
] |
|
|
|
with_dechunk do |
|
body = Rack::Chunked::Body.new body |
|
response = JRuby::Rack::Response.new([200, headers, body]) |
|
response.write_headers(response_environment) |
|
|
|
times = 0 |
|
expect(stream).to receive(:write).exactly(6).times do |bytes| |
|
str = String.from_java_bytes(bytes) |
|
str = str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
case times += 1 |
|
when 1 then expect(str).to eq "1" |
|
when 2 then expect(str).to eq "\nsecond chunk" |
|
when 3 then expect(str).to eq "a multi\nline chunk \n42" |
|
when 4 then expect(str).to eq "utf-8 chunk 'ty píčo'!\n" |
|
when 5 then expect(str).to eq "terminated chunk\r\n" |
|
when 6 then expect(str).to eq "\r\nthe very\r\n last\r\n\r\n chunk" |
|
else |
|
fail("unexpected :write received with #{str.inspect}") |
|
end |
|
end |
|
expect(stream).to receive(:flush).exactly(6 + 1).times # +1 for tail chunk |
|
|
|
response.write_body(response_environment) |
|
end |
|
end |
|
|
|
it "does not dechunk body when dechunkins is turned off", |
|
:lib => [:rails31, :rails32, :rails40] do |
|
dechunk = JRuby::Rack::Response.dechunk? |
|
begin |
|
JRuby::Rack::Response.dechunk = false |
|
|
|
require 'rack/chunked' |
|
headers = { |
|
"Cache-Control" => 'no-cache', |
|
"Transfer-Encoding" => 'chunked' |
|
} |
|
body = [ |
|
"1".freeze, |
|
"\nsecond chunk", |
|
"" |
|
] |
|
body = Rack::Chunked::Body.new body |
|
response = JRuby::Rack::Response.new([200, headers, body]) |
|
|
|
response.write_headers(response_environment) |
|
|
|
times = 0 |
|
expect(stream).to receive(:write).exactly(3).times do |bytes| |
|
str = String.from_java_bytes(bytes) |
|
case times += 1 |
|
when 1 then expect(str).to eq "1\r\n1\r\n" |
|
when 2 then expect(str).to eq "d\r\n\nsecond chunk\r\n" |
|
when 3 then expect(str).to eq "0\r\n\r\n" |
|
else |
|
fail("unexpected :write received with #{str.inspect}") |
|
end |
|
end |
|
expect(stream).to receive(:flush).exactly(3).times |
|
|
|
response.write_body(response_environment) |
|
|
|
ensure |
|
JRuby::Rack::Response.dechunk = dechunk |
|
end |
|
end |
There are some straggler rails version-specific tests/code that are not currently running. Some may have been accidentally omitted from running on newer rails versions; others may have been logic specific to those rails versions that were not actually needed/wanted on newer versions.
jruby-rack/src/spec/ruby/jruby/rack/booter_spec.rb
Line 321 in bbbad30
jruby-rack/src/spec/ruby/jruby/rack/response_spec.rb
Lines 389 to 396 in 6f88954
JRuby::Rack::Response.dechunk = falseis used/needed still).jruby-rack/src/spec/ruby/jruby/rack/response_spec.rb
Lines 156 to 239 in 6f88954
jruby-rack/src/spec/ruby/jruby/rack/response_spec.rb
Lines 377 to 387 in 6f88954
Would also be good to review and remove the associated code if they were specific to ancient rails versions.