mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Properly check #syswrite's value for variable sized buffers. Fixes #170
This commit is contained in:
parent
2e80dec278
commit
021e0f100e
2 changed files with 38 additions and 4 deletions
|
@ -423,7 +423,7 @@ module Puma
|
|||
|
||||
if no_body
|
||||
lines << line_ending
|
||||
client.syswrite lines.to_s
|
||||
fast_write client, lines.to_s
|
||||
return keep_alive
|
||||
end
|
||||
|
||||
|
@ -443,16 +443,16 @@ module Puma
|
|||
|
||||
lines << line_ending
|
||||
|
||||
client.syswrite lines.to_s
|
||||
fast_write client, lines.to_s
|
||||
|
||||
res_body.each do |part|
|
||||
if chunked
|
||||
client.syswrite part.bytesize.to_s(16)
|
||||
client.syswrite line_ending
|
||||
client.syswrite part
|
||||
fast_write client, part
|
||||
client.syswrite line_ending
|
||||
else
|
||||
client.syswrite part
|
||||
fast_write client, part
|
||||
end
|
||||
|
||||
client.flush
|
||||
|
@ -562,5 +562,16 @@ module Puma
|
|||
@persistent_wakeup.close
|
||||
@notify << RESTART_COMMAND
|
||||
end
|
||||
|
||||
def fast_write(io, str)
|
||||
n = io.syswrite str
|
||||
|
||||
# Fast path.
|
||||
return if n == str.bytesize
|
||||
|
||||
# Otherwise go into slow path and use ruby's builtin write logic
|
||||
io.write str[n..-1]
|
||||
end
|
||||
private :fast_write
|
||||
end
|
||||
end
|
||||
|
|
|
@ -102,4 +102,27 @@ class TestPumaServer < Test::Unit::TestCase
|
|||
|
||||
assert_equal body, sock.read
|
||||
end
|
||||
|
||||
def test_very_large_return
|
||||
giant = "x" * 2056610
|
||||
|
||||
@server.app = proc do |env|
|
||||
[200, {}, [giant]]
|
||||
end
|
||||
|
||||
@server.add_tcp_listener @host, @port
|
||||
@server.run
|
||||
|
||||
sock = TCPSocket.new @host, @port
|
||||
sock << "GET / HTTP/1.0\r\n\r\n"
|
||||
|
||||
while true
|
||||
line = sock.gets
|
||||
break if line == "\r\n"
|
||||
end
|
||||
|
||||
out = sock.read
|
||||
|
||||
assert_equal giant.bytesize, out.bytesize
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue