From 123cc5b5acc1ee99366ef2e1e5d4ca7853a7b461 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Tue, 6 Jan 2009 08:54:27 -0800 Subject: [PATCH] Depend on Rack 0.9.0 (up from 0.4.0) * Remove the Rack::MethodOverride class from sinatra since it's included with rack core now. * Update mime type handling to work with Rack 0.9.0's new Rack::Mime module. --- lib/sinatra/base.rb | 14 +++----------- lib/sinatra/compat.rb | 10 ++++++++++ lib/sinatra/main.rb | 7 ++----- lib/sinatra/rack/methodoverride.rb | 21 --------------------- sinatra.gemspec | 2 +- test/helpers_test.rb | 4 ++-- 6 files changed, 18 insertions(+), 40 deletions(-) delete mode 100644 lib/sinatra/rack/methodoverride.rb diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 66ebb820..12ee500c 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -1,7 +1,7 @@ +require 'time' require 'uri' require 'rack' require 'rack/builder' -require 'sinatra/rack/methodoverride' module Sinatra VERSION = '0.9.0' @@ -89,7 +89,8 @@ module Sinatra # Look up a media type by file extension in Rack's mime registry. def media_type(type) return type if type.nil? || type.to_s.include?('/') - Rack::File::MIME_TYPES[type.to_s.sub(/^\./, '')] + type = ".#{type}" unless type.to_s[0] == ?. + Rack::Mime.mime_type(type, nil) end # Set the Content-Type of the response body given a media type or file @@ -771,12 +772,3 @@ module Sinatra base end end - -# Make Rack 0.5.0 backward compatibile with 0.4.0 mime types -require 'rack/file' -class Rack::File - unless defined? MIME_TYPES - MIME_TYPES = Hash.new {|hash,key| - Rack::Mime::MIME_TYPES[".#{key}"] } - end -end diff --git a/lib/sinatra/compat.rb b/lib/sinatra/compat.rb index fba248e0..41ee1add 100644 --- a/lib/sinatra/compat.rb +++ b/lib/sinatra/compat.rb @@ -11,6 +11,16 @@ elsif ENV['EVENT'] puts "Using Evented Mongrel" end +# Deprecated. Make Rack 0.9.0 backward compatibile with 0.4.0 +# mime types +require 'rack/file' +class Rack::File + unless defined? MIME_TYPES + MIME_TYPES = Hash.new {|hash,key| + Rack::Mime::MIME_TYPES[".#{key}"] } + end +end + # Deprecated. Rack::Utils will not extend itself in the future. Sinatra::Base # includes Rack::Utils, however. module Rack::Utils ; extend self ; end diff --git a/lib/sinatra/main.rb b/lib/sinatra/main.rb index b74fb86a..6f5fdb76 100644 --- a/lib/sinatra/main.rb +++ b/lib/sinatra/main.rb @@ -38,14 +38,11 @@ def helpers(&block) end def mime(ext, type) - Rack::File::MIME_TYPES[ext.to_s] = type + ext = ".#{ext}" unless ext.to_s[0] == ?. + Rack::Mime::MIME_TYPES[ext.to_s] = type end at_exit do raise $! if $! Sinatra::Application.run! if Sinatra::Application.run? end - -mime :xml, 'application/xml' -mime :js, 'application/javascript' -mime :png, 'image/png' diff --git a/lib/sinatra/rack/methodoverride.rb b/lib/sinatra/rack/methodoverride.rb deleted file mode 100644 index eb2f0a53..00000000 --- a/lib/sinatra/rack/methodoverride.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Rack - class MethodOverride - HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS) - - def initialize(app) - @app = app - end - - def call(env) - if env["REQUEST_METHOD"] == "POST" - req = Request.new(env) - method = req.POST["_method"].to_s.upcase - if HTTP_METHODS.include?(method) - env["REQUEST_METHOD"] = method - end - end - - @app.call(env) - end - end -end diff --git a/sinatra.gemspec b/sinatra.gemspec index 092cd1fc..229284c7 100644 --- a/sinatra.gemspec +++ b/sinatra.gemspec @@ -96,7 +96,7 @@ Gem::Specification.new do |s| s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/} s.extra_rdoc_files = %w[README.rdoc LICENSE] - s.add_dependency 'rack', '>= 0.4.0' + s.add_dependency 'rack', '>= 0.9.0' s.has_rdoc = true s.homepage = "http://sinatra.rubyforge.org" diff --git a/test/helpers_test.rb b/test/helpers_test.rb index adf28de1..2a2caa3e 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -162,7 +162,7 @@ describe 'Sinatra::Helpers' do describe '#media_type' do include Sinatra::Helpers it "looks up media types in Rack's MIME registry" do - Rack::File::MIME_TYPES['foo'] = 'application/foo' + Rack::Mime::MIME_TYPES['.foo'] = 'application/foo' media_type('foo').should.equal 'application/foo' media_type('.foo').should.equal 'application/foo' media_type(:foo).should.equal 'application/foo' @@ -207,7 +207,7 @@ describe 'Sinatra::Helpers' do end it "looks up symbols in Rack's mime types dictionary" do - Rack::File::MIME_TYPES['foo'] = 'application/foo' + Rack::Mime::MIME_TYPES['.foo'] = 'application/foo' mock_app { get '/foo.xml' do content_type :foo