about summary refs log tree commit homepage
path: root/lib/unicorn/app
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicorn/app')
-rw-r--r--lib/unicorn/app/exec_cgi.rb12
-rw-r--r--lib/unicorn/app/old_rails/static.rb10
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb
index d98b3e4..8f81d78 100644
--- a/lib/unicorn/app/exec_cgi.rb
+++ b/lib/unicorn/app/exec_cgi.rb
@@ -95,10 +95,15 @@ module Unicorn::App
       # Allows +out+ to be used as a Rack body.
       def out.each
         sysseek(@unicorn_app_exec_cgi_offset)
+
+        # don't use a preallocated buffer for sysread since we can't
+        # guarantee an actual socket is consuming the yielded string
+        # (or if somebody is pushing to an array for eventual concatenation
         begin
-          loop { yield(sysread(CHUNK_SIZE)) }
+          yield(sysread(CHUNK_SIZE))
         rescue EOFError
-        end
+          return
+        end while true
       end
 
       prev = nil
@@ -126,7 +131,8 @@ module Unicorn::App
         tmp.binmode
 
         # Rack::Lint::InputWrapper doesn't allow sysread :(
-        while buf = inp.read(CHUNK_SIZE)
+        buf = ''
+        while inp.read(CHUNK_SIZE, buf)
           tmp.syswrite(buf)
         end
         tmp.sysseek(0)
diff --git a/lib/unicorn/app/old_rails/static.rb b/lib/unicorn/app/old_rails/static.rb
index 7ec6b6d..17c007c 100644
--- a/lib/unicorn/app/old_rails/static.rb
+++ b/lib/unicorn/app/old_rails/static.rb
@@ -22,6 +22,8 @@ require 'rack/file'
 class Unicorn::App::OldRails::Static
   FILE_METHODS = { 'GET' => true, 'HEAD' => true }.freeze
   REQUEST_METHOD = 'REQUEST_METHOD'.freeze
+  REQUEST_URI = 'REQUEST_URI'.freeze
+  PATH_INFO = 'PATH_INFO'.freeze
 
   def initialize(app)
     @app = app
@@ -34,10 +36,10 @@ class Unicorn::App::OldRails::Static
     FILE_METHODS.include?(env[REQUEST_METHOD]) or return @app.call(env)
 
     # first try the path as-is
-    path_info = env[Unicorn::Const::PATH_INFO].chomp("/")
+    path_info = env[PATH_INFO].chomp("/")
     if File.file?("#@root/#{::Rack::Utils.unescape(path_info)}")
       # File exists as-is so serve it up
-      env[Unicorn::Const::PATH_INFO] = path_info
+      env[PATH_INFO] = path_info
       return @file_server.call(env)
     end
 
@@ -45,11 +47,11 @@ class Unicorn::App::OldRails::Static
 
     # grab the semi-colon REST operator used by old versions of Rails
     # this is the reason we didn't just copy the new Rails::Rack::Static
-    env[Unicorn::Const::REQUEST_URI] =~ /^#{Regexp.escape(path_info)}(;[^\?]+)/
+    env[REQUEST_URI] =~ /^#{Regexp.escape(path_info)}(;[^\?]+)/
     path_info << "#$1#{ActionController::Base.page_cache_extension}"
 
     if File.file?("#@root/#{::Rack::Utils.unescape(path_info)}")
-      env[Unicorn::Const::PATH_INFO] = path_info
+      env[PATH_INFO] = path_info
       return @file_server.call(env)
     end