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

Fix a POST then GET in a persistent connection

This commit is contained in:
Evan Phoenix 2011-11-22 10:45:58 -08:00
parent 6daeb06688
commit 7ab7b2b9e9
2 changed files with 29 additions and 6 deletions

View file

@ -142,7 +142,11 @@ module Puma
nparsed = parser.execute(env, data, nparsed)
if parser.finished?
return unless handle_request env, client, parser.body
cl = env[CONTENT_LENGTH]
return unless handle_request(env, client, parser.body, cl)
nparsed += parser.body.size if cl
if data.size > nparsed
data.slice!(0, nparsed)
@ -219,10 +223,10 @@ module Puma
env[REMOTE_ADDR] = client.peeraddr.last
end
def handle_request(env, client, body)
def handle_request(env, client, body, cl)
normalize_env env, client
body = read_body env, client, body
body = read_body env, client, body, cl
return false unless body
@ -325,8 +329,8 @@ module Puma
return keep_alive
end
def read_body(env, client, body)
content_length = env[CONTENT_LENGTH].to_i
def read_body(env, client, body, cl)
content_length = cl.to_i
remain = content_length - body.size

View file

@ -1,5 +1,6 @@
require 'puma'
require 'test/unit'
require 'timeout'
class TestPersistent < Test::Unit::TestCase
def setup
@ -8,6 +9,8 @@ class TestPersistent < Test::Unit::TestCase
@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"
@valid_post = "POST / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\nContent-Length: 5\r\n\r\nhello"
@headers = { "X-Header" => "Works" }
@body = ["Hello"]
@simple = lambda { |env| [200, @headers, @body] }
@ -25,7 +28,9 @@ class TestPersistent < Test::Unit::TestCase
def lines(count, s=@client)
str = ""
count.times { str << s.gets }
timeout(5) do
count.times { str << s.gets }
end
str
end
@ -51,6 +56,20 @@ class TestPersistent < Test::Unit::TestCase
assert_equal "Hello", @client.read(5)
end
def test_post_then_get
@client << @valid_post
sz = @body[0].size.to_s
assert_equal "HTTP/1.1 200 OK\r\nX-Header: Works\r\nContent-Length: #{sz}\r\n\r\n", lines(4)
assert_equal "Hello", @client.read(5)
@client << @valid_request
sz = @body[0].size.to_s
assert_equal "HTTP/1.1 200 OK\r\nX-Header: Works\r\nContent-Length: #{sz}\r\n\r\n", lines(4)
assert_equal "Hello", @client.read(5)
end
def test_chunked
@body << "Chunked"