summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-09 16:22:55 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-09 17:53:24 -0700
commitb0013b043a15d77d810d5965157766c1af364db2 (patch)
tree1db783db1387facad6fbdba7e7ea1479b5789898
parentf3e1cd9b7728b85f346d5588268066c9ef9d3cf3 (diff)
Trying not to repeat ourselves.  Unfortunately, Ruby 1.9 forces
us to actually care about encodings of arbitrary byte sequences.
-rw-r--r--lib/unicorn.rb4
-rw-r--r--lib/unicorn/app/inetd.rb3
-rw-r--r--lib/unicorn/chunked_reader.rb3
-rw-r--r--lib/unicorn/http_request.rb2
-rw-r--r--lib/unicorn/http_response.rb3
-rw-r--r--lib/unicorn/tee_input.rb2
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