From 41f6f65a6cb7152b5181704373d7da62704a62e8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 29 Jun 2009 18:01:41 -0700 Subject: chunked_reader: simpler interface This won't be heavily used enough to make preallocation worth the effort. While we're at it, don't enforce policy by forcing the readpartial buffer to be Encoding::BINARY (even though it /should/ be :), it's up to the user of the interface to decide. --- lib/unicorn/chunked_reader.rb | 13 ++----------- lib/unicorn/http_request.rb | 3 +-- 2 files changed, 3 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/unicorn/chunked_reader.rb b/lib/unicorn/chunked_reader.rb index 41193d0..40d421d 100644 --- a/lib/unicorn/chunked_reader.rb +++ b/lib/unicorn/chunked_reader.rb @@ -6,22 +6,13 @@ module Unicorn; end module Unicorn class ChunkedReader - def initialize - @input = @buf = nil - @chunk_left = 0 - end - - def reopen(input, buf) - buf ||= Z.dup - buf.force_encoding(Encoding::BINARY) if buf.respond_to?(:force_encoding) + def initialize(input, buf) @input, @buf = input, buf + @chunk_left = 0 parse_chunk_header - self end def readpartial(max, buf = Z.dup) - buf.force_encoding(Encoding::BINARY) if buf.respond_to?(:force_encoding) - while @input && @chunk_left <= 0 && ! parse_chunk_header @buf << @input.readpartial(Const::CHUNK_SIZE, buf) end diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index b1cd8ed..b2c72f3 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -22,7 +22,6 @@ module Unicorn } NULL_IO = StringIO.new(Z) - DECHUNKER = ChunkedReader.new LOCALHOST = '127.0.0.1'.freeze # Being explicitly single-threaded, we have certain advantages in @@ -93,7 +92,7 @@ module Unicorn if te = PARAMS[Const::HTTP_TRANSFER_ENCODING] if /chunked/i =~ te - socket = DECHUNKER.reopen(socket, body) + socket = ChunkedReader.new(socket, body) length = body = nil end end -- cgit v1.2.3-24-ge0c7