HttpParser#next? becomes response_start_sent-aware
authorEric Wong <normalperson@yhbt.net>
Wed, 8 May 2013 22:57:23 +0000 (8 22:57 +0000)
committerEric Wong <normalperson@yhbt.net>
Wed, 8 May 2013 22:57:23 +0000 (8 22:57 +0000)
This could allow servers with persistent connection support[1]
to support our check_client_connection in the future.

[1] - Rainbows!/zbatery, possibly others

ext/unicorn_http/unicorn_http.rl
test/unit/test_http_parser_ng.rb

index 1a8003f..3529740 100644 (file)
@@ -732,10 +732,8 @@ static VALUE HttpParser_parse(VALUE self)
   struct http_parser *hp = data_get(self);
   VALUE data = hp->buf;
 
-  if (HP_FL_TEST(hp, TO_CLEAR)) {
-    http_parser_init(hp);
-    rb_funcall(hp->env, id_clear, 0);
-  }
+  if (HP_FL_TEST(hp, TO_CLEAR))
+    HttpParser_clear(self);
 
   http_parser_execute(hp, RSTRING_PTR(data), RSTRING_LEN(data));
   if (hp->offset > MAX_HEADER_LEN)
index 93c44bb..ab335ac 100644 (file)
@@ -12,6 +12,23 @@ class HttpParserNgTest < Test::Unit::TestCase
     @parser = HttpParser.new
   end
 
+  def test_next_clear
+    r = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
+    @parser.buf << r
+    @parser.parse
+    @parser.response_start_sent = true
+    assert @parser.keepalive?
+    assert @parser.next?
+    assert @parser.response_start_sent
+
+    # persistent client makes another request:
+    @parser.buf << r
+    @parser.parse
+    assert @parser.keepalive?
+    assert @parser.next?
+    assert_equal false, @parser.response_start_sent
+  end
+
   def test_keepalive_requests_default_constant
     assert_kind_of Integer, HttpParser::KEEPALIVE_REQUESTS_DEFAULT
     assert HttpParser::KEEPALIVE_REQUESTS_DEFAULT >= 0