Prefer Monkey-patching Rack Gem to Vendored Rack

This gets around a dreaded 

  in `load_missing_constant': Rack
  is not missing constant Handler! (ArgumentError)

error in latest Ruby 1.9.2-dev. (Ruby
1.8.x doesn't seem to care.)
master
Jacques Distler 2010-05-08 23:42:40 -05:00
parent 10cf102544
commit fd9fc1455e
3 changed files with 65 additions and 1 deletions

View File

@ -58,8 +58,11 @@ end
require_dependency 'instiki_errors'
#require 'jcode'
# Miscellaneous monkey patches (here be dragons ...)
require 'caching_stuff'
require 'logging_stuff'
require 'rack_stuff'
#Additional Mime-types
mime_types = YAML.load_file(File.join(File.dirname(__FILE__), 'mime_types.yml'))

61
lib/rack_stuff.rb Normal file
View File

@ -0,0 +1,61 @@
require 'webrick'
require 'stringio'
require 'rack/content_length'
require 'tempfile'
module Rack
module Handler
class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet
def self.run(app, options={})
options[:BindAddress] = options.delete(:Host) if options[:Host]
server = ::WEBrick::HTTPServer.new(options)
server.mount "/", Rack::Handler::WEBrick, app
trap(:INT) { server.shutdown }
trap(:TERM) { server.shutdown }
yield server if block_given?
server.start
end
end
end
class RewindableInput
def make_rewindable
# Buffer all data into a tempfile. Since this tempfile is private to this
# RewindableInput object, we chmod it so that nobody else can read or write
# it. On POSIX filesystems we also unlink the file so that it doesn't
# even have a file entry on the filesystem anymore, though we can still
# access it because we have the file handle open.
@rewindable_io = Tempfile.new('RackRewindableInput')
@rewindable_io.chmod(0000)
@rewindable_io.set_encoding(Encoding::BINARY) if @rewindable_io.respond_to?(:set_encoding)
@rewindable_io.binmode
if filesystem_has_posix_semantics? && !tempfile_unlink_contains_bug?
@rewindable_io.unlink
@unlinked = true
end
buffer = ""
while @io.read(1024 * 4, buffer)
entire_buffer_written_out = false
while !entire_buffer_written_out
written = @rewindable_io.write(buffer)
entire_buffer_written_out = written == buffer.size
if !entire_buffer_written_out
buffer.slice!(0 .. written - 1)
end
end
end
@rewindable_io.rewind
end
def tempfile_unlink_contains_bug?
# The tempfile library as included in Ruby 1.9.1-p152 and later
# contains a bug: unlinking an open Tempfile object also closes
# it, which breaks our expected POSIX semantics. This problem
# has been fixed in Ruby 1.9.2, but the Ruby team chose not to
# include the bug fix in later versions of the 1.9.1 series.
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
ruby_engine == "ruby" && RUBY_VERSION == "1.9.1" && RUBY_PATCHLEVEL >= 152
end
end
end

View File

@ -32,7 +32,7 @@ rescue LoadError
end
begin
gem 'rack', '~> 1.1.1'
gem 'rack', '~> 1.1.0'
require 'rack'
rescue Gem::LoadError
$:.unshift "#{File.dirname(__FILE__)}/../../../plugins/rack/lib"