Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chunked ending check #1607

Merged
merged 2 commits into from Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/puma/client.rb
Expand Up @@ -168,6 +168,7 @@ def decode_chunk(chunk)
if len == 0
@body.rewind
rest = io.read
rest = rest[2..-1] if rest.start_with?("\r\n")
@buffer = rest.empty? ? nil : rest
@requests_served += 1
@ready = true
Expand Down
49 changes: 49 additions & 0 deletions test/test_puma_server.rb
Expand Up @@ -677,6 +677,55 @@ def test_chunked_request_header_case
assert_equal "hello", body
end

def test_chunked_keep_alive
body = nil
@server.app = proc { |env|
body = env['rack.input'].read
[200, {}, [""]]
}

@server.add_tcp_listener @host, @port
@server.run

sock = TCPSocket.new @host, @server.connected_port
sock << "GET / HTTP/1.1\r\nConnection: Keep-Alive\r\nTransfer-Encoding: chunked\r\n\r\n1\r\nh\r\n4\r\nello\r\n0\r\n\r\n"

h = header(sock)

assert_equal ["HTTP/1.1 200 OK", "Content-Length: 0"], h
assert_equal "hello", body

sock.close
end

def test_chunked_keep_alive_two_back_to_back
body = nil
@server.app = proc { |env|
body = env['rack.input'].read
[200, {}, [""]]
}

@server.add_tcp_listener @host, @port
@server.run

sock = TCPSocket.new @host, @server.connected_port
sock << "GET / HTTP/1.1\r\nConnection: Keep-Alive\r\nTransfer-Encoding: chunked\r\n\r\n1\r\nh\r\n4\r\nello\r\n0\r\n\r\n"

h = header(sock)
assert_equal ["HTTP/1.1 200 OK", "Content-Length: 0"], h
assert_equal "hello", body

sock << "GET / HTTP/1.1\r\nConnection: Keep-Alive\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ngood\r\n3\r\nbye\r\n0\r\n\r\n"
sleep 0.1

h = header(sock)

assert_equal ["HTTP/1.1 200 OK", "Content-Length: 0"], h
assert_equal "goodbye", body

sock.close
end

def test_empty_header_values
@server.app = proc { |env| [200, {"X-Empty-Header" => ""}, []] }

Expand Down