1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

proper persistent connection behavior for HTTP 1.0

This commit is contained in:
Konstantin Haase 2011-10-03 14:28:46 -07:00 committed by Evan Phoenix
parent 3085156d2e
commit 357b3cbbe7
2 changed files with 27 additions and 2 deletions

View file

@ -213,7 +213,14 @@ module Puma
env["rack.input"] = body
env["rack.url_scheme"] = env["HTTPS"] ? "https" : "http"
keep_alive = env["HTTP_CONNECTION"] != "close"
if env['HTTP_VERSION'] == 'HTTP/1.1'
http_version = "HTTP/1.1 "
keep_alive = env["HTTP_CONNECTION"] != "close"
else
http_version = "HTTP/1.0 "
keep_alive = env["HTTP_CONNECTION"] == "Keep-Alive"
end
chunked = false
begin
@ -231,7 +238,7 @@ module Puma
content_length = res_body[0].size
end
client.write "HTTP/1.1 "
client.write http_version
client.write status.to_s
client.write " "
client.write HTTP_STATUS_CODES[status]

View file

@ -5,6 +5,8 @@ class TestPersistent < Test::Unit::TestCase
def setup
@valid_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\n\r\n"
@close_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n"
@http10_request = "GET / HTTP/1.0\r\nHost: test.com\r\nContent-Type: text/plain\r\n\r\n"
@keep_request = "GET / HTTP/1.0\r\nHost: test.com\r\nContent-Type: text/plain\r\nConnection: Keep-Alive\r\n\r\n"
@headers = { "X-Header" => "Works" }
@body = ["Hello"]
@ -75,4 +77,20 @@ class TestPersistent < Test::Unit::TestCase
assert_equal "Hello", @client.read(5)
end
def test_client_close
@client << @http10_request
sz = @body[0].size.to_s
assert_equal "HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Length: #{sz}\r\nX-Header: Works\r\n\r\n", lines(5)
assert_equal "Hello", @client.read(5)
end
def test_one_with_keep_alive_header
@client << @keep_request
sz = @body[0].size.to_s
assert_equal "HTTP/1.0 200 OK\r\nContent-Length: #{sz}\r\nX-Header: Works\r\n\r\n", lines(4)
assert_equal "Hello", @client.read(5)
end
end