mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Fix early termination of headers bug
This commit is contained in:
parent
89ea73cee5
commit
bcb630c017
2 changed files with 15 additions and 6 deletions
|
@ -213,7 +213,7 @@ module Puma
|
|||
env["rack.input"] = body
|
||||
env["rack.url_scheme"] = env["HTTPS"] ? "https" : "http"
|
||||
|
||||
keep_alive = env["Connection"] != "close"
|
||||
keep_alive = env["HTTP_CONNECTION"] != "close"
|
||||
chunked = false
|
||||
|
||||
begin
|
||||
|
@ -235,15 +235,14 @@ module Puma
|
|||
client.write status.to_s
|
||||
client.write " "
|
||||
client.write HTTP_STATUS_CODES[status]
|
||||
client.write "\r\n"
|
||||
|
||||
unless keep_alive
|
||||
client.write "\r\nConnection: close\r\n"
|
||||
end
|
||||
client.write "Connection: close\r\n" unless keep_alive
|
||||
|
||||
if content_length
|
||||
client.write "\r\nContent-Length: #{content_length}\r\n"
|
||||
client.write "Content-Length: #{content_length}\r\n"
|
||||
else
|
||||
client.write "\r\nTransfer-Encoding: chunked\r\n"
|
||||
client.write "Transfer-Encoding: chunked\r\n"
|
||||
chunked = true
|
||||
end
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ require 'test/unit'
|
|||
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"
|
||||
|
||||
@headers = { "X-Header" => "Works" }
|
||||
@body = ["Hello"]
|
||||
@simple = lambda { |env| [200, @headers, @body] }
|
||||
|
@ -65,4 +67,12 @@ class TestPersistent < Test::Unit::TestCase
|
|||
|
||||
end
|
||||
|
||||
def test_client_close
|
||||
@client << @close_request
|
||||
sz = @body[0].size.to_s
|
||||
|
||||
assert_equal "HTTP/1.1 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
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue