From 32b6e838c28b7948811a6470d8c0a49d5767ec69 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 24 Mar 2009 02:35:26 -0700 Subject: simplify the HttpParser interface This cuts the HttpParser interface down to #execute and #reset method. HttpParser#execute will return true if it completes and false if it is not. http->nread state is kept internally so we don't have to keep track of it in Ruby; removing one parameter from #execute. HttpParser#reset is unchanged. All errors are handled through exceptions anyways, so the HttpParser#error? method stopped being useful. Also added some more unit tests to the HttpParser since I know some folks are (rightfully) uncomfortable with changing stable C code. We now have tests for incremental parsing. In summary, we have: * more test cases * less C code * simpler interfaces * small performance improvement => win \o/ --- lib/unicorn/http_request.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index ef6ce05..04386fc 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -57,8 +57,8 @@ module Unicorn # to handle any socket errors (e.g. user aborted upload). def read(socket) # short circuit the common case with small GET requests first - nparsed = @parser.execute(@params, read_socket(socket), 0) - @parser.finished? and return handle_body(socket) + @parser.execute(@params, read_socket(socket)) and + return handle_body(socket) data = @buffer.dup # read_socket will clobber @buffer @@ -66,8 +66,8 @@ module Unicorn # an Exception thrown from the @parser will throw us out of the loop loop do data << read_socket(socket) - nparsed = @parser.execute(@params, data, nparsed) - @parser.finished? and return handle_body(socket) + @parser.execute(@params, data) and + return handle_body(socket) end rescue HttpParserError => e @logger.error "HTTP parse error, malformed request " \ -- cgit v1.2.3-24-ge0c7