From e99178ef89eca9e46b73484aaf9733259dac9dca Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 Oct 2010 08:12:36 +0000 Subject: http: fix behavior with pipelined requests We cannot clear the buffer between requests because clients may send multiple requests that get taken in one read()/recv() call. --- ext/unicorn_http/unicorn_http.rl | 1 - test/unit/test_http_parser_ng.rb | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3-24-ge0c7