1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

ship with our own rack backports

This commit is contained in:
Konstantin Haase 2011-03-21 11:50:06 +01:00
parent 1463863e9c
commit d0557f57c7
2 changed files with 46 additions and 13 deletions

View file

@ -1,8 +1,7 @@
require 'thread'
require 'time'
require 'uri'
require 'rack'
require 'rack/builder'
require 'sinatra/rack'
require 'sinatra/showexceptions'
require 'tilt'
@ -17,17 +16,7 @@ module Sinatra
@env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.split(';')[0].strip }
end
if Rack.release <= "1.2"
# Whether or not the web server (or a reverse proxy in front of it) is
# using SSL to communicate with the client.
def secure?
@env['HTTPS'] == 'on' or
@env['HTTP_X_FORWARDED_PROTO'] == 'https' or
@env['rack.url_scheme'] == 'https'
end
else
alias secure? ssl?
end
alias secure? ssl?
def forwarded?
@env.include? "HTTP_X_FORWARDED_HOST"

44
lib/sinatra/rack.rb Normal file
View file

@ -0,0 +1,44 @@
# Rack is rather slow on releases at the moment. Moreover, we cannot upgrade to
# a new Rack version right away, as this would make us incompatible with Rails.
# We therefore apply fixes that have not yet made it into a Rack release here.
#
# The code in here is extracted from the Rack project.
#
# Copyright (C) 2007, 2008, 2009, 2010 Christian Neukirchen <purl.org/net/chneukirchen>
#
# Rack is freely distributable under the terms of an MIT-style license.
# See http://www.opensource.org/licenses/mit-license.php.
require 'rack'
if Rack.release <= "1.2"
require 'rack/request'
require 'rack/logger'
require 'rack/methodoverride'
module Rack
class Request
def ssl?
@env['HTTPS'] == 'on' or
@env['HTTP_X_FORWARDED_PROTO'] == 'https' or
@env['rack.url_scheme'] == 'https'
end
end
class Logger
# In Rack 1.2 and earlier, Rack::Logger called env['rack.errors'].close,
# which is forbidden in the SPEC and made it impossible to use Rack::Lint.
# Also, it might close your log file after the first request, potentially
# crashing your web server.
def call(env)
logger = ::Logger.new(env['rack.errors'])
logger.level = @level
env['rack.logger'] = logger
@app.call(env)
end
end
class MethodOverride
HTTP_METHODS << "PATCH"
end
end
end