From b0013b043a15d77d810d5965157766c1af364db2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 9 Jun 2009 16:22:55 -0700 Subject: Avoid duplicating the "Z" constant Trying not to repeat ourselves. Unfortunately, Ruby 1.9 forces us to actually care about encodings of arbitrary byte sequences. --- lib/unicorn.rb | 4 ++++ lib/unicorn/app/inetd.rb | 3 --- lib/unicorn/chunked_reader.rb | 3 --- lib/unicorn/http_request.rb | 2 -- lib/unicorn/http_response.rb | 3 +-- lib/unicorn/tee_input.rb | 2 -- 6 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index f45c613..13da564 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -14,6 +14,10 @@ module Unicorn autoload :ChunkedReader, 'unicorn/chunked_reader' autoload :Util, 'unicorn/util' + Z = '' # the stock empty string we use everywhere... + Z.force_encoding(Encoding::BINARY) if Z.respond_to?(:force_encoding) + Z.freeze + class << self def run(app, options = {}) HttpServer.new(app, options).start.join diff --git a/lib/unicorn/app/inetd.rb b/lib/unicorn/app/inetd.rb index 4938508..54f8a86 100644 --- a/lib/unicorn/app/inetd.rb +++ b/lib/unicorn/app/inetd.rb @@ -6,9 +6,6 @@ module Unicorn::App class Inetd - Z = '' - Z.force_encoding(Encoding::BINARY) if Z.respond_to?(:force_encoding) - class CatBody def initialize(env, cmd) @cmd = cmd diff --git a/lib/unicorn/chunked_reader.rb b/lib/unicorn/chunked_reader.rb index a16a4e5..41193d0 100644 --- a/lib/unicorn/chunked_reader.rb +++ b/lib/unicorn/chunked_reader.rb @@ -6,9 +6,6 @@ module Unicorn; end module Unicorn class ChunkedReader - Z = '' - Z.force_encoding(Encoding::BINARY) if Z.respond_to?(:force_encoding) - def initialize @input = @buf = nil @chunk_left = 0 diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 025b125..58a5554 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -26,8 +26,6 @@ module Unicorn "SERVER_SOFTWARE" => "Unicorn #{Const::UNICORN_VERSION}".freeze } - Z = '' - Z.force_encoding(Encoding::BINARY) if Z.respond_to?(:force_encoding) NULL_IO = StringIO.new(Z) TEE = TeeInput.new DECHUNKER = ChunkedReader.new diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb index 15df3f6..bfaa33d 100644 --- a/lib/unicorn/http_response.rb +++ b/lib/unicorn/http_response.rb @@ -31,7 +31,6 @@ module Unicorn # Connection: and Date: headers no matter what (if anything) our # Rack application sent us. SKIP = { 'connection' => true, 'date' => true, 'status' => true }.freeze - EMPTY = ''.freeze # :nodoc OUT = [] # :nodoc # writes the rack_response to socket as an HTTP response @@ -59,7 +58,7 @@ module Unicorn "Date: #{Time.now.httpdate}\r\n" \ "Status: #{status}\r\n" \ "Connection: close\r\n" \ - "#{OUT.join(EMPTY)}\r\n") + "#{OUT.join(Z)}\r\n") body.each { |chunk| socket.write(chunk) } socket.close # flushes and uncorks the socket immediately ensure diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index a1d3190..9c4dda2 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -14,8 +14,6 @@ require 'tempfile' module Unicorn class TeeInput - Z = '' - Z.force_encoding(Encoding::BINARY) if Z.respond_to?(:force_encoding) def initialize @rd = @wr = @size = @input = nil -- cgit v1.2.3-24-ge0c7