mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
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.
This commit is contained in:
parent
54b9ecf3e1
commit
123cc5b5ac
6 changed files with 18 additions and 40 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue