mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
request.rb - fix chunked assembly for ascii incompatible encodings, add test (#2585)
Fix TestPumaServer#test_custom_io_selector
This commit is contained in:
parent
1acb30d68d
commit
403975b372
2 changed files with 28 additions and 3 deletions
|
@ -148,8 +148,9 @@ module Puma
|
|||
res_body.each do |part|
|
||||
next if part.bytesize.zero?
|
||||
if chunked
|
||||
str = part.bytesize.to_s(16) << line_ending << part << line_ending
|
||||
fast_write io, str
|
||||
fast_write io, (part.bytesize.to_s(16) << line_ending)
|
||||
fast_write io, part # part may have different encoding
|
||||
fast_write io, line_ending
|
||||
else
|
||||
fast_write io, part
|
||||
end
|
||||
|
|
|
@ -839,6 +839,31 @@ EOF
|
|||
sock.close
|
||||
end
|
||||
|
||||
def test_chunked_encoding
|
||||
enc = Encoding::UTF_16LE
|
||||
str = "──иї_テスト──\n".encode enc
|
||||
|
||||
server_run app: ->(env) {
|
||||
hdrs = {}
|
||||
hdrs['Content-Type'] = "text; charset=#{enc.to_s.downcase}"
|
||||
|
||||
body = Enumerator.new do |yielder|
|
||||
100.times do |entry|
|
||||
yielder << str
|
||||
end
|
||||
yielder << "\nHello World\n".encode(enc)
|
||||
end
|
||||
|
||||
[200, hdrs, body]
|
||||
}
|
||||
|
||||
body = Net::HTTP.start @host, @port do |http|
|
||||
http.request(Net::HTTP::Get.new '/').body.force_encoding(enc)
|
||||
end
|
||||
assert_includes body, str
|
||||
assert_equal enc, body.encoding
|
||||
end
|
||||
|
||||
def test_empty_header_values
|
||||
server_run app: ->(env) { [200, {"X-Empty-Header" => ""}, []] }
|
||||
|
||||
|
@ -1180,7 +1205,6 @@ EOF
|
|||
|
||||
@server = Puma::Server.new @app, @events, {:io_selector_backend => backend}
|
||||
@server.run
|
||||
@server.stop
|
||||
|
||||
selector = @server.instance_variable_get(:@reactor).instance_variable_get(:@selector)
|
||||
|
||||
|
|
Loading…
Reference in a new issue