Skip to content

Commit

Permalink
request.rb - fix chunked assembly for ascii incompatible encodings, a…
Browse files Browse the repository at this point in the history
…dd test (#2585)

Fix TestPumaServer#test_custom_io_selector
  • Loading branch information
MSP-Greg committed Mar 26, 2021
1 parent 1acb30d commit 403975b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/puma/request.rb
Expand Up @@ -148,8 +148,9 @@ def handle_request(client, lines)
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
Expand Down
26 changes: 25 additions & 1 deletion test/test_puma_server.rb
Expand Up @@ -839,6 +839,31 @@ def test_chunked_keep_alive_two_back_to_back_with_set_remote_address
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" => ""}, []] }

Expand Down Expand Up @@ -1180,7 +1205,6 @@ def test_custom_io_selector

@server = Puma::Server.new @app, @events, {:io_selector_backend => backend}
@server.run
@server.stop

selector = @server.instance_variable_get(:@reactor).instance_variable_get(:@selector)

Expand Down

0 comments on commit 403975b

Please sign in to comment.