diff --git a/Gemfile b/Gemfile index 46deda1f21..5164f4c908 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index fa637e6fc0..d37fd2ae33 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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 diff --git a/passenger.gemspec b/passenger.gemspec index b13a3c8428..19900c6384 100644 --- a/passenger.gemspec +++ b/passenger.gemspec @@ -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 + diff --git a/src/ruby_supportlib/phusion_passenger/rack/handler.rb b/src/ruby_supportlib/phusion_passenger/rack/handler.rb new file mode 100644 index 0000000000..d6f36559f7 --- /dev/null +++ b/src/ruby_supportlib/phusion_passenger/rack/handler.rb @@ -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 diff --git a/src/ruby_supportlib/phusion_passenger/rack_handler.rb b/src/ruby_supportlib/phusion_passenger/rack_handler.rb index 48c471a02b..f6132da4c5 100644 --- a/src/ruby_supportlib/phusion_passenger/rack_handler.rb +++ b/src/ruby_supportlib/phusion_passenger/rack_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Phusion Passenger - https://www.phusionpassenger.com/ # Copyright (c) 2016-2017 Phusion Holding B.V. # @@ -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