Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Compatibility for Rack 3 (Rails > 7.1) #2507

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ source 'https://rubygems.org/'
group :base do
gem 'json', '= 2.5.1'
gem 'mime-types', '1.25'
gem 'rack', '< 2.0'
gem 'rack', '>= 3'
gem 'rackup', '>= 2.1'
gem 'rake', '< 13.0.0'
gem 'rspec', '~> 3.0.0'
gem 'rspec-collection_matchers'
Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ GEM
diff-lcs (1.5.0)
json (2.5.1)
mime-types (1.25)
rack (1.6.13)
rack (3.0.8)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rake (12.3.3)
rspec (3.0.0)
rspec-core (~> 3.0.0)
Expand All @@ -28,9 +31,12 @@ PLATFORMS
DEPENDENCIES
json (= 2.5.1)
mime-types (= 1.25)
rack (< 2.0)
rack (>= 3)
rackup (>= 2.1)
rake (< 13.0.0)
rspec (~> 3.0.0)
rspec-collection_matchers
webrick (~> 1.8.1)

BUNDLED WITH
2.4.21
1 change: 1 addition & 0 deletions passenger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Gem::Specification.new do |s|
}
s.add_dependency 'rake', '>= 0.8.1'
s.add_dependency 'rack'
s.add_dependency 'rackup'
s.files = Dir[*PhusionPassenger::Packaging::GLOB] -
Dir[*PhusionPassenger::Packaging::EXCLUDE_GLOB]
s.executables = PhusionPassenger::Packaging::USER_EXECUTABLES +
Expand Down
71 changes: 71 additions & 0 deletions src/ruby_supportlib/phusion_passenger/rack/handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

# Phusion Passenger - https://www.phusionpassenger.com/
# Copyright (c) 2010-2017 Phusion Holding B.V.
#
# "Passenger", "Phusion Passenger" and "Union Station" are registered
# trademarks of Phusion Holding B.V.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

module PhusionPassenger
module Rack
module Handler
def run(_app, options = {})
return if system(ruby_executable, '-S', find_passenger_standalone, 'start', *build_args(options))

raise 'Error starting Passenger'
end

def environment
ENV['RAILS_ENV'] || 'development'
end

def to_s
'Passenger application server'
end

private

def build_args(options)
args = ['-e', environment]
args << '-p' << options[:Port].to_s if options[:Port]
args << '-a' << options[:Host].to_s if options[:Host]
args << '-R' << options[:config].to_s if options[:config]
args
end

def rb_config
if defined?(::RbConfig)
::RbConfig::CONFIG
else
::Config::CONFIG
end
end

def ruby_executable
@ruby_executable ||= "#{rb_config['bindir']}/#{rb_config['RUBY_INSTALL_NAME']}#{rb_config['EXEEXT']}"
end

def find_passenger_standalone
::File.join(::PhusionPassenger.bin_dir, 'passenger')
end
end
end
end
85 changes: 30 additions & 55 deletions src/ruby_supportlib/phusion_passenger/rack_handler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Phusion Passenger - https://www.phusionpassenger.com/
# Copyright (c) 2016-2017 Phusion Holding B.V.
#
Expand Down Expand Up @@ -27,76 +29,49 @@
$LOAD_PATH.unshift(libdir)
begin
require 'rubygems'
require 'rackup'
rescue LoadError
end
require 'phusion_passenger'
require_relative 'rack/handler'
## Magic comment: end bootstrap ##

PhusionPassenger.locate_directories

require 'rbconfig'

module Rack
module Handler
class PhusionPassenger
class << self
def run(app, options = {})
result = system(ruby_executable, '-S', find_passenger_standalone,
'start', *build_args(options))
if !result
raise "Error starting Passenger"
end
end

def environment
ENV['RAILS_ENV'] || 'development'
end

def to_s
'Passenger application server'
end

private
def build_args(options)
args = ['-e', environment]
if options[:Port]
args << '-p'
args << options[:Port].to_s
end
if options[:Host]
args << '-a'
args << options[:Host].to_s
end
if options[:config]
args << '-R'
args << options[:config].to_s
end
args
end

def rb_config
if defined?(::RbConfig)
::RbConfig::CONFIG
else
::Config::CONFIG
end
# Rackup was removed in Rack 3, it is now a separate gem
if Object.const_defined? :Rackup
module Rackup
module Handler
module PhusionPassenger
class << self
include ::PhusionPassenger::Rack::Handler
end
end

def ruby_executable
@ruby_executable ||= rb_config['bindir'] + '/' +
rb_config['RUBY_INSTALL_NAME'] + rb_config['EXEEXT']
end
def self.default(options = {})
::Rackup::Handler::PhusionPassenger
end

def find_passenger_standalone
::File.join(::PhusionPassenger.bin_dir, 'passenger')
register :passenger, PhusionPassenger
end
end
elsif Object.const_defined?(:Rack) && Rack.release < '3'
module Rack
module Handler
module PhusionPassenger
class << self
include ::PhusionPassenger::Rack::Handler
end
end
end

register 'passenger', 'Rack::Handler::PhusionPassenger'

def self.default(options = {})
Rack::Handler::PhusionPassenger
def self.default(options = {})
::Rack::Handler::PhusionPassenger
end
end
end
::Rack::Handler.register(:passenger, ::Rack::Handler::PhusionPassenger)
else
raise 'Rack 3 must be used with the Rackup gem'
end