mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Send the proper headers to HTTP/1.0 in keep-alive
Seems that an HTTP/1.0 client needs to be told that the connection is still in keep alive mode by setting the Connection header to Keep-Alive. This makes sense because a server could deny the request and thus no Connection header means close mode.
This commit is contained in:
parent
a96bc75fe0
commit
d0a2fac2ac
2 changed files with 8 additions and 2 deletions
|
@ -245,9 +245,11 @@ module Puma
|
|||
allow_chunked = true
|
||||
http_version = "HTTP/1.1 "
|
||||
keep_alive = env["HTTP_CONNECTION"] != "close"
|
||||
include_keepalive_header = false
|
||||
else
|
||||
http_version = "HTTP/1.0 "
|
||||
keep_alive = env["HTTP_CONNECTION"] == "Keep-Alive"
|
||||
include_keepalive_header = keep_alive
|
||||
end
|
||||
|
||||
chunked = false
|
||||
|
@ -294,7 +296,11 @@ module Puma
|
|||
end
|
||||
end
|
||||
|
||||
client.write "Connection: close\r\n" unless keep_alive
|
||||
if include_keepalive_header
|
||||
client.write "Connection: Keep-Alive\r\n"
|
||||
elsif !keep_alive
|
||||
client.write "Connection: close\r\n"
|
||||
end
|
||||
|
||||
if content_length
|
||||
client.write "Content-Length: #{content_length}\r\n"
|
||||
|
|
|
@ -123,7 +123,7 @@ class TestPersistent < Test::Unit::TestCase
|
|||
@client << @keep_request
|
||||
sz = @body[0].size.to_s
|
||||
|
||||
assert_equal "HTTP/1.0 200 OK\r\nX-Header: Works\r\nContent-Length: #{sz}\r\n\r\n", lines(4)
|
||||
assert_equal "HTTP/1.0 200 OK\r\nX-Header: Works\r\nConnection: Keep-Alive\r\nContent-Length: #{sz}\r\n\r\n", lines(5)
|
||||
assert_equal "Hello", @client.read(5)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue