summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-05-26 14:45:18 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-05-26 14:45:18 -0700
commite4b71e6b993773fca06467c161fa0f89eede9a0a (patch)
tree01a4a4ff65cdf5a8095f58700fe0374a88ff00e9
parent30406b968384c56dd3b77add927e81046c9fb107 (diff)
parent8e60fee51aad9abe91ab84c11efd7ff5da04fb61 (diff)
downloadrack-e4b71e6b993773fca06467c161fa0f89eede9a0a.tar.gz
Merge pull request #870 from deepj/cleanup-ruby22
Initial clean up and preparation for Ruby 2.2+ only support
-rw-r--r--Gemfile1
-rw-r--r--README.rdoc9
-rw-r--r--lib/rack/chunked.rb4
-rw-r--r--lib/rack/content_length.rb2
-rw-r--r--lib/rack/deflater.rb1
-rw-r--r--lib/rack/directory.rb22
-rw-r--r--lib/rack/file.rb14
-rw-r--r--lib/rack/handler.rb6
-rw-r--r--lib/rack/handler/evented_mongrel.rb8
-rw-r--r--lib/rack/handler/mongrel.rb106
-rw-r--r--lib/rack/handler/scgi.rb3
-rw-r--r--lib/rack/handler/swiftiplied_mongrel.rb8
-rw-r--r--lib/rack/handler/webrick.rb2
-rw-r--r--lib/rack/lint.rb2
-rw-r--r--lib/rack/mime.rb5
-rw-r--r--lib/rack/mock.rb5
-rw-r--r--lib/rack/multipart/generator.rb6
-rw-r--r--lib/rack/multipart/parser.rb80
-rw-r--r--lib/rack/multipart/uploaded_file.rb3
-rw-r--r--lib/rack/request.rb1
-rw-r--r--lib/rack/response.rb2
-rw-r--r--lib/rack/rewindable_input.rb13
-rw-r--r--lib/rack/sendfile.rb6
-rw-r--r--lib/rack/showexceptions.rb2
-rw-r--r--lib/rack/showstatus.rb2
-rw-r--r--lib/rack/urlmap.rb19
-rw-r--r--lib/rack/utils.rb34
-rw-r--r--test/spec_commonlogger.rb3
-rw-r--r--test/spec_deflater.rb10
-rw-r--r--test/spec_handler.rb5
-rw-r--r--test/spec_mongrel.rb182
-rw-r--r--test/spec_utils.rb8
32 files changed, 92 insertions, 482 deletions
diff --git a/Gemfile b/Gemfile
index d764d402..9acb9a8c 100644
--- a/Gemfile
+++ b/Gemfile
@@ -18,6 +18,5 @@ end
group :extra do
gem 'fcgi', :platforms => c_platforms
gem 'memcache-client'
- gem 'mongrel', '>= 1.2.0.pre2', :platforms => c_platforms
gem 'thin', :platforms => c_platforms
end
diff --git a/README.rdoc b/README.rdoc
index fcbc6903..8f186534 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -12,9 +12,6 @@ which all Rack applications should conform to.
== Supported web servers
The included *handlers* connect all kinds of web servers to Rack:
-* Mongrel
-* EventedMongrel
-* SwiftipliedMongrel
* WEBrick
* FCGI
* CGI
@@ -101,8 +98,8 @@ Rack::Builder DSL to configure middleware and build up applications
easily.
rackup automatically figures out the environment it is run in, and
-runs your application as FastCGI, CGI, or standalone with Mongrel or
-WEBrick---all from the same configuration.
+runs your application as FastCGI, CGI, or WEBrick---all from the
+same configuration.
== Quick start
@@ -151,7 +148,6 @@ To run the test suite completely, you need:
* fcgi
* memcache-client
- * mongrel
* thin
The full set of tests test FCGI access with lighttpd (on port
@@ -307,4 +303,3 @@ rack-devel mailing list:: <https://groups.google.com/group/rack-devel>
Rack's Rubyforge project:: <http://rubyforge.org/projects/rack>
Christian Neukirchen:: <http://chneukirchen.org/>
-
diff --git a/lib/rack/chunked.rb b/lib/rack/chunked.rb
index e15223bb..4b8f270e 100644
--- a/lib/rack/chunked.rb
+++ b/lib/rack/chunked.rb
@@ -21,10 +21,10 @@ module Rack
def each
term = TERM
@body.each do |chunk|
- size = bytesize(chunk)
+ size = chunk.bytesize
next if size == 0
- chunk = chunk.dup.force_encoding(Encoding::BINARY) if chunk.respond_to?(:force_encoding)
+ chunk = chunk.dup.force_encoding(Encoding::BINARY)
yield [size.to_s(16), term, chunk, term].join
end
yield TAIL
diff --git a/lib/rack/content_length.rb b/lib/rack/content_length.rb
index a7f34e79..2df7dfc8 100644
--- a/lib/rack/content_length.rb
+++ b/lib/rack/content_length.rb
@@ -22,7 +22,7 @@ module Rack
obody = body
body, length = [], 0
- obody.each { |part| body << part; length += bytesize(part) }
+ obody.each { |part| body << part; length += part.bytesize }
body = BodyProxy.new(body) do
obody.close if obody.respond_to?(:close)
diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb
index 817556a3..5c61294f 100644
--- a/lib/rack/deflater.rb
+++ b/lib/rack/deflater.rb
@@ -119,7 +119,6 @@ module Rack
deflator = ::Zlib::Deflate.new(*DEFLATE_ARGS)
@body.each { |part| yield deflator.deflate(part, Zlib::SYNC_FLUSH) }
yield deflator.finish
- nil
ensure
deflator.close
end
diff --git a/lib/rack/directory.rb b/lib/rack/directory.rb
index 5f111320..cee83d41 100644
--- a/lib/rack/directory.rb
+++ b/lib/rack/directory.rb
@@ -43,7 +43,7 @@ table { width:100%%; }
attr_accessor :root, :path
def initialize(root, app=nil)
- @root = F.expand_path(root)
+ @root = ::File.expand_path(root)
@app = app || Rack::File.new(@root)
end
@@ -51,8 +51,6 @@ table { width:100%%; }
dup._call(env)
end
- F = ::File
-
def _call(env)
@env = env
@script_name = env[SCRIPT_NAME]
@@ -61,7 +59,7 @@ table { width:100%%; }
if forbidden = check_forbidden
forbidden
else
- @path = F.join(@root, @path_info)
+ @path = ::File.join(@root, @path_info)
list_path
end
end
@@ -70,7 +68,7 @@ table { width:100%%; }
return unless @path_info.include? ".."
body = "Forbidden\n"
- size = Rack::Utils.bytesize(body)
+ size = body.bytesize
return [403, {CONTENT_TYPE => "text/plain",
CONTENT_LENGTH => size.to_s,
"X-Cascade" => "pass"}, [body]]
@@ -78,7 +76,7 @@ table { width:100%%; }
def list_directory
@files = [['../','Parent Directory','','','']]
- glob = F.join(@path, '*')
+ glob = ::File.join(@path, '*')
url_head = (@script_name.split('/') + @path_info.split('/')).map do |part|
Rack::Utils.escape part
@@ -87,10 +85,10 @@ table { width:100%%; }
Dir[glob].sort.each do |node|
stat = stat(node)
next unless stat
- basename = F.basename(node)
- ext = F.extname(node)
+ basename = ::File.basename(node)
+ ext = ::File.extname(node)
- url = F.join(*url_head + [Rack::Utils.escape(basename)])
+ url = ::File.join(*url_head + [Rack::Utils.escape(basename)])
size = stat.size
type = stat.directory? ? 'directory' : Mime.mime_type(ext)
size = stat.directory? ? '-' : filesize_format(size)
@@ -105,7 +103,7 @@ table { width:100%%; }
end
def stat(node, max = 10)
- F.stat(node)
+ ::File.stat(node)
rescue Errno::ENOENT, Errno::ELOOP
return nil
end
@@ -113,7 +111,7 @@ table { width:100%%; }
# TODO: add correct response if not readable, not sure if 404 is the best
# option
def list_path
- @stat = F.stat(@path)
+ @stat = ::File.stat(@path)
if @stat.readable?
return @app.call(@env) if @stat.file?
@@ -128,7 +126,7 @@ table { width:100%%; }
def entity_not_found
body = "Entity not found: #{@path_info}\n"
- size = Rack::Utils.bytesize(body)
+ size = body.bytesize
return [404, {CONTENT_TYPE => "text/plain",
CONTENT_LENGTH => size.to_s,
"X-Cascade" => "pass"}, [body]]
diff --git a/lib/rack/file.rb b/lib/rack/file.rb
index 08b6e6c5..165972eb 100644
--- a/lib/rack/file.rb
+++ b/lib/rack/file.rb
@@ -31,8 +31,6 @@ module Rack
dup._call(env)
end
- F = ::File
-
def _call(env)
unless ALLOWED_VERBS.include? env[REQUEST_METHOD]
return fail(405, "Method Not Allowed", {'Allow' => ALLOW_HEADER})
@@ -41,10 +39,10 @@ module Rack
path_info = Utils.unescape(env[PATH_INFO])
clean_path_info = Utils.clean_path_info(path_info)
- @path = F.join(@root, clean_path_info)
+ @path = ::File.join(@root, clean_path_info)
available = begin
- F.file?(@path) && F.readable?(@path)
+ ::File.file?(@path) && ::File.readable?(@path)
rescue SystemCallError
false
end
@@ -60,7 +58,7 @@ module Rack
if env[REQUEST_METHOD] == OPTIONS
return [200, {'Allow' => ALLOW_HEADER, CONTENT_LENGTH => '0'}, []]
end
- last_modified = F.mtime(@path).httpdate
+ last_modified = ::File.mtime(@path).httpdate
return [304, {}, []] if env['HTTP_IF_MODIFIED_SINCE'] == last_modified
headers = { "Last-Modified" => last_modified }
@@ -99,7 +97,7 @@ module Rack
end
def each
- F.open(@path, "rb") do |file|
+ ::File.open(@path, "rb") do |file|
file.seek(@range.begin)
remaining_len = @range.end-@range.begin+1
while remaining_len > 0
@@ -129,7 +127,7 @@ module Rack
# The MIME type for the contents of the file located at @path
def mime_type
- Mime.mime_type(F.extname(@path), @default_mime)
+ Mime.mime_type(::File.extname(@path), @default_mime)
end
def filesize
@@ -139,7 +137,7 @@ module Rack
# We check via File::size? whether this file provides size info
# via stat (e.g. /proc files often don't), otherwise we have to
# figure it out by reading the whole file into memory.
- F.size?(@path) || Utils.bytesize(F.read(@path))
+ ::File.size?(@path) || ::File.read(@path).bytesize
end
# By default, the response body for file requests is nil.
diff --git a/lib/rack/handler.rb b/lib/rack/handler.rb
index 5794f7d7..512bff36 100644
--- a/lib/rack/handler.rb
+++ b/lib/rack/handler.rb
@@ -84,9 +84,6 @@ module Rack
autoload :CGI, "rack/handler/cgi"
autoload :FastCGI, "rack/handler/fastcgi"
- autoload :Mongrel, "rack/handler/mongrel"
- autoload :EventedMongrel, "rack/handler/evented_mongrel"
- autoload :SwiftipliedMongrel, "rack/handler/swiftiplied_mongrel"
autoload :WEBrick, "rack/handler/webrick"
autoload :LSWS, "rack/handler/lsws"
autoload :SCGI, "rack/handler/scgi"
@@ -94,9 +91,6 @@ module Rack
register 'cgi', 'Rack::Handler::CGI'
register 'fastcgi', 'Rack::Handler::FastCGI'
- register 'mongrel', 'Rack::Handler::Mongrel'
- register 'emongrel', 'Rack::Handler::EventedMongrel'
- register 'smongrel', 'Rack::Handler::SwiftipliedMongrel'
register 'webrick', 'Rack::Handler::WEBrick'
register 'lsws', 'Rack::Handler::LSWS'
register 'scgi', 'Rack::Handler::SCGI'
diff --git a/lib/rack/handler/evented_mongrel.rb b/lib/rack/handler/evented_mongrel.rb
deleted file mode 100644
index 0f5cbf72..00000000
--- a/lib/rack/handler/evented_mongrel.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'swiftcore/evented_mongrel'
-
-module Rack
- module Handler
- class EventedMongrel < Handler::Mongrel
- end
- end
-end
diff --git a/lib/rack/handler/mongrel.rb b/lib/rack/handler/mongrel.rb
deleted file mode 100644
index af0e7cd1..00000000
--- a/lib/rack/handler/mongrel.rb
+++ /dev/null
@@ -1,106 +0,0 @@
-require 'mongrel'
-require 'stringio'
-require 'rack/content_length'
-require 'rack/chunked'
-
-module Rack
- module Handler
- class Mongrel < ::Mongrel::HttpHandler
- def self.run(app, options={})
- environment = ENV['RACK_ENV'] || 'development'
- default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
-
- server = ::Mongrel::HttpServer.new(
- options[:Host] || default_host,
- options[:Port] || 8080,
- options[:num_processors] || 950,
- options[:throttle] || 0,
- options[:timeout] || 60)
- # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
- # Use is similar to #run, replacing the app argument with a hash of
- # { path=>app, ... } or an instance of Rack::URLMap.
- if options[:map]
- if app.is_a? Hash
- app.each do |path, appl|
- path = '/'+path unless path[0] == ?/
- server.register(path, Rack::Handler::Mongrel.new(appl))
- end
- elsif app.is_a? URLMap
- app.instance_variable_get(:@mapping).each do |(host, path, appl)|
- next if !host.nil? && !options[:Host].nil? && options[:Host] != host
- path = '/'+path unless path[0] == ?/
- server.register(path, Rack::Handler::Mongrel.new(appl))
- end
- else
- raise ArgumentError, "first argument should be a Hash or URLMap"
- end
- else
- server.register('/', Rack::Handler::Mongrel.new(app))
- end
- yield server if block_given?
- server.run.join
- end
-
- def self.valid_options
- environment = ENV['RACK_ENV'] || 'development'
- default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
-
- {
- "Host=HOST" => "Hostname to listen on (default: #{default_host})",
- "Port=PORT" => "Port to listen on (default: 8080)",
- "Processors=N" => "Number of concurrent processors to accept (default: 950)",
- "Timeout=N" => "Time before a request is dropped for inactivity (default: 60)",
- "Throttle=N" => "Throttle time between socket.accept calls in hundredths of a second (default: 0)",
- }
- end
-
- def initialize(app)
- @app = app
- end
-
- def process(request, response)
- env = Hash[request.params]
- env.delete "HTTP_CONTENT_TYPE"
- env.delete "HTTP_CONTENT_LENGTH"
-
- env[SCRIPT_NAME] = "" if env[SCRIPT_NAME] == "/"
-
- rack_input = request.body || StringIO.new('')
- rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
-
- env.update({"rack.version" => Rack::VERSION,
- "rack.input" => rack_input,
- "rack.errors" => $stderr,
-
- "rack.multithread" => true,
- "rack.multiprocess" => false, # ???
- "rack.run_once" => false,
-
- "rack.url_scheme" => ["yes", "on", "1"].include?(env[HTTPS]) ? "https" : "http"
- })
- env[QUERY_STRING] ||= ""
-
- status, headers, body = @app.call(env)
-
- begin
- response.status = status.to_i
- response.send_status(nil)
-
- headers.each { |k, vs|
- vs.split("\n").each { |v|
- response.header[k] = v
- }
- }
- response.send_header
-
- body.each { |part|
- response.write part
- response.socket.flush
- }
- ensure
- body.close if body.respond_to? :close
- end
- end
- end
- end
-end
diff --git a/lib/rack/handler/scgi.rb b/lib/rack/handler/scgi.rb
index 8d3eea26..2e54e050 100644
--- a/lib/rack/handler/scgi.rb
+++ b/lib/rack/handler/scgi.rb
@@ -41,8 +41,7 @@ module Rack
env[QUERY_STRING] ||= ""
env[SCRIPT_NAME] = ""
- rack_input = StringIO.new(input_body)
- rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
+ rack_input = StringIO.new(input_body, encoding: Encoding::BINARY)
env.update({"rack.version" => Rack::VERSION,
"rack.input" => rack_input,
diff --git a/lib/rack/handler/swiftiplied_mongrel.rb b/lib/rack/handler/swiftiplied_mongrel.rb
deleted file mode 100644
index 4bafd0b9..00000000
--- a/lib/rack/handler/swiftiplied_mongrel.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'swiftcore/swiftiplied_mongrel'
-
-module Rack
- module Handler
- class SwiftipliedMongrel < Handler::Mongrel
- end
- end
-end
diff --git a/lib/rack/handler/webrick.rb b/lib/rack/handler/webrick.rb
index 992f813a..76e07f59 100644
--- a/lib/rack/handler/webrick.rb
+++ b/lib/rack/handler/webrick.rb
@@ -60,7 +60,7 @@ module Rack
env.delete_if { |k, v| v.nil? }
rack_input = StringIO.new(req.body.to_s)
- rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
+ rack_input.set_encoding(Encoding::BINARY)
env.update({"rack.version" => Rack::VERSION,
"rack.input" => rack_input,
diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb
index 2931ab4a..49d775df 100644
--- a/lib/rack/lint.rb
+++ b/lib/rack/lint.rb
@@ -710,7 +710,7 @@ module Rack
assert("Body yielded non-string value #{part.inspect}") {
part.kind_of? String
}
- bytes += Rack::Utils.bytesize(part)
+ bytes += part.bytesize
yield part
}
verify_content_length(bytes)
diff --git a/lib/rack/mime.rb b/lib/rack/mime.rb
index 26a2fab6..d82dc131 100644
--- a/lib/rack/mime.rb
+++ b/lib/rack/mime.rb
@@ -45,11 +45,6 @@ module Rack
#
# N.B. On Ubuntu the mime.types file does not include the leading period, so
# users may need to modify the data before merging into the hash.
- #
- # To add the list mongrel provides, use:
- #
- # require 'mongrel/handlers'
- # Rack::Mime::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES)
MIME_TYPES = {
".123" => "application/vnd.lotus-1-2-3",
diff --git a/lib/rack/mock.rb b/lib/rack/mock.rb
index ae50fd41..8d1e0635 100644
--- a/lib/rack/mock.rb
+++ b/lib/rack/mock.rb
@@ -128,8 +128,7 @@ module Rack
end
end
- empty_str = ""
- empty_str.force_encoding("ASCII-8BIT") if empty_str.respond_to? :force_encoding
+ empty_str = ''.force_encoding(Encoding::ASCII_8BIT)
opts[:input] ||= empty_str
if String === opts[:input]
rack_input = StringIO.new(opts[:input])
@@ -137,7 +136,7 @@ module Rack
rack_input = opts[:input]
end
- rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
+ rack_input.set_encoding(Encoding::BINARY)
env['rack.input'] = rack_input
env["CONTENT_LENGTH"] ||= env["rack.input"].length.to_s
diff --git a/lib/rack/multipart/generator.rb b/lib/rack/multipart/generator.rb
index 1c586b75..edf11669 100644
--- a/lib/rack/multipart/generator.rb
+++ b/lib/rack/multipart/generator.rb
@@ -15,8 +15,8 @@ module Rack
flattened_params.map do |name, file|
if file.respond_to?(:original_filename)
- ::File.open(file.path, "rb") do |f|
- f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding)
+ ::File.open(file.path, 'rb') do |f|
+ f.set_encoding(Encoding::BINARY)
content_for_tempfile(f, file, name)
end
else
@@ -90,4 +90,4 @@ EOF
end
end
end
-end \ No newline at end of file
+end
diff --git a/lib/rack/multipart/parser.rb b/lib/rack/multipart/parser.rb
index 29e50427..c47c5f37 100644
--- a/lib/rack/multipart/parser.rb
+++ b/lib/rack/multipart/parser.rb
@@ -27,17 +27,13 @@ module Rack
end
def initialize(boundary, io, content_length, env, tempfile, bufsize)
- @buf = ""
-
- if @buf.respond_to? :force_encoding
- @buf.force_encoding Encoding::ASCII_8BIT
- end
+ @buf = "".force_encoding(Encoding::ASCII_8BIT)
@params = Utils::KeySpaceConstrainedParams.new
@boundary = "--#{boundary}"
@io = io
@content_length = content_length
- @boundary_size = Utils.bytesize(@boundary) + EOL.size
+ @boundary_size = @boundary.bytesize + EOL.size
@env = env
@tempfile = tempfile
@bufsize = bufsize
@@ -104,17 +100,13 @@ module Rack
return if read_buffer == full_boundary
end
- raise EOFError, "bad content body" if Utils.bytesize(@buf) >= @bufsize
+ raise EOFError, "bad content body" if @buf.bytesize >= @bufsize
end
end
def get_current_head_and_filename_and_content_type_and_name_and_body
head = nil
- body = ''
-
- if body.respond_to? :force_encoding
- body.force_encoding Encoding::ASCII_8BIT
- end
+ body = ''.force_encoding(Encoding::ASCII_8BIT)
filename = content_type = name = nil
@@ -172,7 +164,7 @@ module Rack
filename = Utils.unescape(filename)
end
- scrub_filename filename
+ scrub_filename(filename)
if filename !~ /\\[^\\"]/
filename = filename.gsub(/\\(.)/, '\1')
@@ -180,51 +172,45 @@ module Rack
filename
end
- if "<3".respond_to? :valid_encoding?
- def scrub_filename(filename)
- unless filename.valid_encoding?
- # FIXME: this force_encoding is for Ruby 2.0 and 1.9 support.
- # We can remove it after they are dropped
- filename.force_encoding(Encoding::ASCII_8BIT)
- filename.encode!(:invalid => :replace, :undef => :replace)
- end
+ def scrub_filename(filename)
+ unless filename.valid_encoding?
+ # FIXME: this force_encoding is for Ruby 2.0 and 1.9 support.
+ # We can remove it after they are dropped
+ filename.force_encoding(Encoding::ASCII_8BIT)
+ filename.encode!(:invalid => :replace, :undef => :replace)
end
+ end
- CHARSET = "charset"
+ CHARSET = "charset"
- def tag_multipart_encoding(filename, content_type, name, body)
- name = name.to_s
- name.force_encoding Encoding::UTF_8
+ def tag_multipart_encoding(filename, content_type, name, body)
+ name = name.to_s
+ encoding = Encoding::UTF_8
- return if filename
+ name.force_encoding(encoding)
- encoding = Encoding::UTF_8
+ return if filename
- if content_type
- list = content_type.split(';')
- type_subtype = list.first
- type_subtype.strip!
- if TEXT_PLAIN == type_subtype
- rest = list.drop 1
- rest.each do |param|
- k,v = param.split('=', 2)
- k.strip!
- v.strip!
- encoding = Encoding.find v if k == CHARSET
- end
+ if content_type
+ list = content_type.split(';')
+ type_subtype = list.first
+ type_subtype.strip!
+ if TEXT_PLAIN == type_subtype
+ rest = list.drop 1
+ rest.each do |param|
+ k,v = param.split('=', 2)
+ k.strip!
+ v.strip!
+ encoding = Encoding.find v if k == CHARSET
end
end
-
- name.force_encoding encoding
- body.force_encoding encoding
- end
- else
- def scrub_filename(filename)
- end
- def tag_multipart_encoding(filename, content_type, name, body)
end
+
+ name.force_encoding(encoding)
+ body.force_encoding(encoding)
end
+
def get_data(filename, body, content_type, name, head)
data = body
if filename == ""
diff --git a/lib/rack/multipart/uploaded_file.rb b/lib/rack/multipart/uploaded_file.rb
index 1b56ad75..924b1f08 100644
--- a/lib/rack/multipart/uploaded_file.rb
+++ b/lib/rack/multipart/uploaded_file.rb
@@ -11,8 +11,7 @@ module Rack
raise "#{path} file does not exist" unless ::File.exist?(path)
@content_type = content_type
@original_filename = ::File.basename(path)
- @tempfile = Tempfile.new([@original_filename, ::File.extname(path)])
- @tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
+ @tempfile = Tempfile.new([@original_filename, ::File.extname(path)], encoding: Encoding::BINARY)
@tempfile.binmode if binary
FileUtils.copy_file(path, @tempfile.path)
end
diff --git a/lib/rack/request.rb b/lib/rack/request.rb
index 7167f338..69729ba6 100644
--- a/lib/rack/request.rb
+++ b/lib/rack/request.rb
@@ -257,7 +257,6 @@ module Rack
self.GET[k] = v
end
@params = nil
- nil
end
# Destructively delete a parameter, whether it's in GET or POST. Returns the value of the deleted parameter.
diff --git a/lib/rack/response.rb b/lib/rack/response.rb
index a57f12fc..e615f60b 100644
--- a/lib/rack/response.rb
+++ b/lib/rack/response.rb
@@ -97,7 +97,7 @@ module Rack
#
def write(str)
s = str.to_s
- @length += Rack::Utils.bytesize(s) unless @chunked
+ @length += s.bytesize unless @chunked
@writer.call s
header[CONTENT_LENGTH] = @length.to_s unless @chunked
diff --git a/lib/rack/rewindable_input.rb b/lib/rack/rewindable_input.rb
index 15ecc586..dd6b7843 100644
--- a/lib/rack/rewindable_input.rb
+++ b/lib/rack/rewindable_input.rb
@@ -57,15 +57,6 @@ module Rack
private
- # Ruby's Tempfile class has a bug. Subclass it and fix it.
- class Tempfile < ::Tempfile
- def _close
- @tmpfile.close if @tmpfile
- @data[1] = nil if @data
- @tmpfile = nil
- end
- end
-
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
@@ -77,8 +68,6 @@ module Rack
@rewindable_io.set_encoding(Encoding::BINARY) if @rewindable_io.respond_to?(:set_encoding)
@rewindable_io.binmode
if filesystem_has_posix_semantics?
- # Use ::File.unlink as 1.9.1 Tempfile has a bug where unlink closes the file!
- ::File.unlink @rewindable_io.path
raise 'Unlink failed. IO closed.' if @rewindable_io.closed?
@unlinked = true
end
@@ -88,7 +77,7 @@ module Rack
entire_buffer_written_out = false
while !entire_buffer_written_out
written = @rewindable_io.write(buffer)
- entire_buffer_written_out = written == Rack::Utils.bytesize(buffer)
+ entire_buffer_written_out = written == buffer.bytesize
if !entire_buffer_written_out
buffer.slice!(0 .. written - 1)
end
diff --git a/lib/rack/sendfile.rb b/lib/rack/sendfile.rb
index 4a9b428b..99045d7f 100644
--- a/lib/rack/sendfile.rb
+++ b/lib/rack/sendfile.rb
@@ -99,8 +99,6 @@ module Rack
# will be matched with case indifference.
class Sendfile
- F = ::File
-
def initialize(app, variation=nil, mappings=[])
@app = app
@variation = variation
@@ -114,7 +112,7 @@ module Rack
if body.respond_to?(:to_path)
case type = variation(env)
when 'X-Accel-Redirect'
- path = F.expand_path(body.to_path)
+ path = ::File.expand_path(body.to_path)
if url = map_accel_path(env, path)
headers[CONTENT_LENGTH] = '0'
headers[type] = url
@@ -126,7 +124,7 @@ module Rack
env['rack.errors'].puts "X-Accel-Mapping header missing"
end
when 'X-Sendfile', 'X-Lighttpd-Send-File'
- path = F.expand_path(body.to_path)
+ path = ::File.expand_path(body.to_path)
headers[CONTENT_LENGTH] = '0'
headers[type] = path
obody = body
diff --git a/lib/rack/showexceptions.rb b/lib/rack/showexceptions.rb
index 60999e64..ca1ba37c 100644
--- a/lib/rack/showexceptions.rb
+++ b/lib/rack/showexceptions.rb
@@ -40,7 +40,7 @@ module Rack
500,
{
CONTENT_TYPE => content_type,
- CONTENT_LENGTH => Rack::Utils.bytesize(body).to_s,
+ CONTENT_LENGTH => body.bytesize.to_s,
},
[body],
]
diff --git a/lib/rack/showstatus.rb b/lib/rack/showstatus.rb
index 4426310a..430b7d84 100644
--- a/lib/rack/showstatus.rb
+++ b/lib/rack/showstatus.rb
@@ -34,7 +34,7 @@ module Rack
detail = detail = env["rack.showstatus.detail"] || message
body = @template.result(binding)
- size = Rack::Utils.bytesize(body)
+ size = body.bytesize
[status, headers.merge(CONTENT_TYPE => "text/html", CONTENT_LENGTH => size.to_s), [body]]
else
[status, headers, body]
diff --git a/lib/rack/urlmap.rb b/lib/rack/urlmap.rb
index d9b021d4..572b2151 100644
--- a/lib/rack/urlmap.rb
+++ b/lib/rack/urlmap.rb
@@ -41,17 +41,17 @@ module Rack
end
def call(env)
- path = env[PATH_INFO]
+ path = env[PATH_INFO]
script_name = env[SCRIPT_NAME]
- hHost = env[HTTP_HOST]
- sName = env[SERVER_NAME]
- sPort = env[SERVER_PORT]
+ http_host = env[HTTP_HOST]
+ server_name = env[SERVER_NAME]
+ server_port = env[SERVER_PORT]
@mapping.each do |host, location, match, app|
- unless casecmp?(hHost, host) \
- || casecmp?(sName, host) \
- || (!host && (casecmp?(hHost, sName) ||
- casecmp?(hHost, sName+':'+sPort)))
+ unless casecmp?(http_host, host) \
+ || casecmp?(server_name, host) \
+ || (!host && (casecmp?(http_host, server_name) ||
+ casecmp?(http_host, "#{server_name}:#{server_port}")))
next
end
@@ -69,7 +69,7 @@ module Rack
[404, {CONTENT_TYPE => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]]
ensure
- env[PATH_INFO] = path
+ env[PATH_INFO] = path
env[SCRIPT_NAME] = script_name
end
@@ -87,4 +87,3 @@ module Rack
end
end
end
-
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index 0ce1ea97..52aecfe0 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -36,14 +36,8 @@ module Rack
# Unescapes a URI escaped string with +encoding+. +encoding+ will be the
# target encoding of the string returned, and it defaults to UTF-8
- if defined?(::Encoding)
- def unescape(s, encoding = Encoding::UTF_8)
- URI.decode_www_form_component(s, encoding)
- end
- else
- def unescape(s, encoding = nil)
- URI.decode_www_form_component(s, encoding)
- end
+ def unescape(s, encoding = Encoding::UTF_8)
+ URI.decode_www_form_component(s, encoding)
end
module_function :unescape
@@ -221,13 +215,8 @@ module Rack
'"' => "&quot;",
"/" => "&#x2F;"
}
- if //.respond_to?(:encoding)
- ESCAPE_HTML_PATTERN = Regexp.union(*ESCAPE_HTML.keys)
- else
- # On 1.8, there is a kcode = 'u' bug that allows for XSS otherwise
- # TODO doesn't apply to jruby, so a better condition above might be preferable?
- ESCAPE_HTML_PATTERN = /#{Regexp.union(*ESCAPE_HTML.keys)}/n
- end
+
+ ESCAPE_HTML_PATTERN = Regexp.union(*ESCAPE_HTML.keys)
# Escape ampersands, brackets and quotes to their HTML/XML entities.
def escape_html(string)
@@ -360,19 +349,6 @@ module Rack
end
module_function :delete_cookie_header!
- # Return the bytesize of String; uses String#size under Ruby 1.8 and
- # String#bytesize under 1.9.
- if ''.respond_to?(:bytesize)
- def bytesize(string)
- string.bytesize
- end
- else
- def bytesize(string)
- string.size
- end
- end
- module_function :bytesize
-
def rfc2822(time)
time.rfc2822
end
@@ -434,7 +410,7 @@ module Rack
# on variable length plaintext strings because it could leak length info
# via timing attacks.
def secure_compare(a, b)
- return false unless bytesize(a) == bytesize(b)
+ return false unless a.bytesize == b.bytesize
l = a.unpack("C*")
diff --git a/test/spec_commonlogger.rb b/test/spec_commonlogger.rb
index fd1f2521..e0585313 100644
--- a/test/spec_commonlogger.rb
+++ b/test/spec_commonlogger.rb
@@ -58,13 +58,14 @@ describe Rack::CommonLogger do
end
def with_mock_time(t = 0)
- mc = class <<Time; self; end
+ mc = class << Time; self; end
mc.send :alias_method, :old_now, :now
mc.send :define_method, :now do
at(t)
end
yield
ensure
+ mc.send :undef_method, :now
mc.send :alias_method, :now, :old_now
end
diff --git a/test/spec_deflater.rb b/test/spec_deflater.rb
index 7893b572..4e784796 100644
--- a/test/spec_deflater.rb
+++ b/test/spec_deflater.rb
@@ -321,19 +321,19 @@ describe Rack::Deflater do
end
should "check for Content-Length via :if" do
- body = 'Hello World!'
- body_len = body.length
+ response = 'Hello World!'
+ response_len = response.length
options = {
'response_headers' => {
- 'Content-Length' => body_len.to_s
+ 'Content-Length' => response_len.to_s
},
'deflater_options' => {
:if => lambda { |env, status, headers, body|
- headers['Content-Length'].to_i >= body_len
+ headers['Content-Length'].to_i >= response_len
}
}
}
- verify(200, body, 'gzip', options)
+ verify(200, response, 'gzip', options)
end
end
diff --git a/test/spec_handler.rb b/test/spec_handler.rb
index e8f41fdc..fb6a1f4b 100644
--- a/test/spec_handler.rb
+++ b/test/spec_handler.rb
@@ -12,11 +12,6 @@ describe Rack::Handler do
Rack::Handler.get('fastcgi').should.equal Rack::Handler::FastCGI
rescue LoadError
end
-
- begin
- Rack::Handler.get('mongrel').should.equal Rack::Handler::Mongrel
- rescue LoadError
- end
end
should "raise LoadError if handler doesn't exist" do
diff --git a/test/spec_mongrel.rb b/test/spec_mongrel.rb
deleted file mode 100644
index 6399ad0b..00000000
--- a/test/spec_mongrel.rb
+++ /dev/null
@@ -1,182 +0,0 @@
-begin
-require 'rack'
-require 'rack/handler/mongrel'
-require File.expand_path('../testrequest', __FILE__)
-require 'timeout'
-
-Thread.abort_on_exception = true
-$tcp_defer_accept_opts = nil
-$tcp_cork_opts = nil
-
-describe Rack::Handler::Mongrel do
- extend TestRequest::Helpers
-
- @server = Mongrel::HttpServer.new(@host='127.0.0.1', @port=9201)
- @server.register('/test',
- Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new)))
- @server.register('/stream',
- Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest)))
- @acc = @server.run
-
- should "respond" do
- lambda {
- GET("/test")
- }.should.not.raise
- end
-
- should "be a Mongrel" do
- GET("/test")
- status.should.equal 200
- response["SERVER_SOFTWARE"].should =~ /Mongrel/
- response["HTTP_VERSION"].should.equal "HTTP/1.1"
- response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
- response["SERVER_PORT"].should.equal "9201"
- response["SERVER_NAME"].should.equal "127.0.0.1"
- end
-
- should "have rack headers" do
- GET("/test")
- response["rack.version"].should.equal [1,3]
- response["rack.multithread"].should.be.true
- response["rack.multiprocess"].should.be.false
- response["rack.run_once"].should.be.false
- end
-
- should "have CGI headers on GET" do
- GET("/test")
- response["REQUEST_METHOD"].should.equal "GET"
- response["SCRIPT_NAME"].should.equal "/test"
- response["REQUEST_PATH"].should.equal "/test"
- response["PATH_INFO"].should.be.equal ""
- response["QUERY_STRING"].should.equal ""
- response["test.postdata"].should.equal ""
-
- GET("/test/foo?quux=1")
- response["REQUEST_METHOD"].should.equal "GET"
- response["SCRIPT_NAME"].should.equal "/test"
- response["REQUEST_PATH"].should.equal "/test/foo"
- response["PATH_INFO"].should.equal "/foo"
- response["QUERY_STRING"].should.equal "quux=1"
- end
-
- should "have CGI headers on POST" do
- POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
- status.should.equal 200
- response["REQUEST_METHOD"].should.equal "POST"
- response["SCRIPT_NAME"].should.equal "/test"
- response["REQUEST_PATH"].should.equal "/test"
- response["QUERY_STRING"].should.equal ""
- response["HTTP_X_TEST_HEADER"].should.equal "42"
- response["test.postdata"].should.equal "rack-form-data=23"
- end
-
- should "support HTTP auth" do
- GET("/test", {:user => "ruth", :passwd => "secret"})
- response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
- end
-
- should "set status" do
- GET("/test?secret")
- status.should.equal 403
- response["rack.url_scheme"].should.equal "http"
- end
-
- should "provide a .run" do
- block_ran = false
- Thread.new {
- Rack::Handler::Mongrel.run(lambda {}, {:Host => '127.0.0.1', :Port => 9211}) { |server|
- server.should.be.kind_of Mongrel::HttpServer
- block_ran = true
- }
- }
- sleep 1
- block_ran.should.be.true
- end
-
- should "provide a .run that maps a hash" do
- block_ran = false
- Thread.new {
- map = {'/'=>lambda{},'/foo'=>lambda{}}
- Rack::Handler::Mongrel.run(map, :map => true, :Host => '127.0.0.1', :Port => 9221) { |server|
- server.should.be.kind_of Mongrel::HttpServer
- server.classifier.uris.size.should.equal 2
- server.classifier.uris.should.not.include '/arf'
- server.classifier.uris.should.include '/'
- server.classifier.uris.should.include '/foo'
- block_ran = true
- }
- }
- sleep 1
- block_ran.should.be.true
- end
-
- should "provide a .run that maps a urlmap" do
- block_ran = false
- Thread.new {
- map = Rack::URLMap.new({'/'=>lambda{},'/bar'=>lambda{}})
- Rack::Handler::Mongrel.run(map, {:map => true, :Host => '127.0.0.1', :Port => 9231}) { |server|
- server.should.be.kind_of Mongrel::HttpServer
- server.classifier.uris.size.should.equal 2
- server.classifier.uris.should.not.include '/arf'
- server.classifier.uris.should.include '/'
- server.classifier.uris.should.include '/bar'
- block_ran = true
- }
- }
- sleep 1
- block_ran.should.be.true
- end
-
- should "provide a .run that maps a urlmap restricting by host" do
- block_ran = false
- Thread.new {
- map = Rack::URLMap.new({
- '/' => lambda{},
- '/foo' => lambda{},
- '/bar' => lambda{},
- 'http://127.0.0.1/' => lambda{},
- 'http://127.0.0.1/bar' => lambda{},
- 'http://falsehost/arf' => lambda{},
- 'http://falsehost/qux' => lambda{}
- })
- opt = {:map => true, :Port => 9241, :Host => '127.0.0.1'}
- Rack::Handler::Mongrel.run(map, opt) { |server|
- server.should.be.kind_of Mongrel::HttpServer
- server.classifier.uris.should.include '/'
- server.classifier.handler_map['/'].size.should.equal 2
- server.classifier.uris.should.include '/foo'
- server.classifier.handler_map['/foo'].size.should.equal 1
- server.classifier.uris.should.include '/bar'
- server.classifier.handler_map['/bar'].size.should.equal 2
- server.classifier.uris.should.not.include '/qux'
- server.classifier.uris.should.not.include '/arf'
- server.classifier.uris.size.should.equal 3
- block_ran = true
- }
- }
- sleep 1
- block_ran.should.be.true
- end
-
- should "stream #each part of the response" do
- body = ''
- begin
- Timeout.timeout(1) do
- Net::HTTP.start(@host, @port) do |http|
- get = Net::HTTP::Get.new('/stream')
- http.request(get) do |response|
- response.read_body { |part| body << part }
- end
- end
- end
- rescue Timeout::Error
- end
- body.should.not.be.empty
- end
-
- @acc.raise Mongrel::StopServer
-end
-
-rescue LoadError
- warn "Skipping Rack::Handler::Mongrel tests (Mongrel is required). `gem install mongrel` and try again."
-end
diff --git a/test/spec_utils.rb b/test/spec_utils.rb
index 7e33cd89..37755373 100644
--- a/test/spec_utils.rb
+++ b/test/spec_utils.rb
@@ -6,7 +6,7 @@ require 'timeout'
describe Rack::Utils do
# A helper method which checks
- # if certain query parameters
+ # if certain query parameters
# are equal.
def equal_query_to(query)
parts = query.split('&')
@@ -48,7 +48,7 @@ describe Rack::Utils do
Rack::Utils.escape("ΓΈ".encode("ISO-8859-1")).should.equal "%F8"
end
end
-
+
should "not hang on escaping long strings that end in % (http://redmine.ruby-lang.org/issues/5149)" do
lambda {
timeout(1) do
@@ -376,10 +376,6 @@ describe Rack::Utils do
helper.call(%w(foo bar baz identity), [["*", 0], ["identity", 0.1]]).should.equal("identity")
end
- should "return the bytesize of String" do
- Rack::Utils.bytesize("FOO\xE2\x82\xAC").should.equal 6
- end
-
should "should perform constant time string comparison" do
Rack::Utils.secure_compare('a', 'a').should.equal true
Rack::Utils.secure_compare('a', 'b').should.equal false