summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-07 08:12:36 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-07 08:14:14 +0000
commite99178ef89eca9e46b73484aaf9733259dac9dca (patch)
tree52098695f4b7fff6ce11839edcd929cda9204849
parenteb5ba488422020568e5ccf650891d7fccce7238f (diff)
We cannot clear the buffer between requests because
clients may send multiple requests that get taken in
one read()/recv() call.
-rw-r--r--ext/unicorn_http/unicorn_http.rl1
-rw-r--r--test/unit/test_http_parser_ng.rb25
2 files changed, 25 insertions, 1 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 1e81c34..236fbaa 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -496,7 +496,6 @@ static VALUE HttpParser_reset(VALUE self)
 
   http_parser_init(hp);
   rb_funcall(hp->env, id_clear, 0);
-  rb_str_set_len(hp->buf, 0);
 
   return Qnil;
 }
diff --git a/test/unit/test_http_parser_ng.rb b/test/unit/test_http_parser_ng.rb
index ec82b8a..65b843e 100644
--- a/test/unit/test_http_parser_ng.rb
+++ b/test/unit/test_http_parser_ng.rb
@@ -473,4 +473,29 @@ class HttpParserNgTest < Test::Unit::TestCase
     assert_equal expect, req
   end
 
+  def test_pipelined_requests
+    expect = {
+      "HTTP_HOST" => "example.com",
+      "SERVER_NAME" => "example.com",
+      "REQUEST_PATH" => "/",
+      "rack.url_scheme" => "http",
+      "SERVER_PROTOCOL" => "HTTP/1.1",
+      "PATH_INFO" => "/",
+      "HTTP_VERSION" => "HTTP/1.1",
+      "REQUEST_URI" => "/",
+      "SERVER_PORT" => "80",
+      "REQUEST_METHOD" => "GET",
+      "QUERY_STRING" => ""
+    }
+    str = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
+    @parser.buf << (str * 2)
+    env1 = @parser.parse.dup
+    assert_equal expect, env1
+    assert_equal str, @parser.buf
+    assert @parser.keepalive?
+    @parser.reset
+    env2 = @parser.parse.dup
+    assert_equal expect, env2
+    assert_equal "", @parser.buf
+  end
 end