From d0d239d011a8a115efec02b66c142bfd45bdc45a Mon Sep 17 00:00:00 2001 From: Andrea Lorenzetti Date: Sun, 2 Feb 2025 14:22:11 +0100 Subject: [PATCH 1/3] Support rack 3.x and rackup * fixed register Thin with rack/rackup --- gems/rack-head.rb | 1 + gems/rack-v3.rb | 1 + lib/rack/handler/thin.rb | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gems/rack-head.rb b/gems/rack-head.rb index d3001cbe..b898223b 100644 --- a/gems/rack-head.rb +++ b/gems/rack-head.rb @@ -3,3 +3,4 @@ eval_gemfile "../Gemfile" gem 'rack', github: 'rack/rack' +gem 'rackup' diff --git a/gems/rack-v3.rb b/gems/rack-v3.rb index 01923819..5f767d9d 100644 --- a/gems/rack-v3.rb +++ b/gems/rack-v3.rb @@ -3,3 +3,4 @@ eval_gemfile "../Gemfile" gem 'rack', "~> 3.0" +gem 'rackup' diff --git a/lib/rack/handler/thin.rb b/lib/rack/handler/thin.rb index bfa03cd5..24698cb9 100644 --- a/lib/rack/handler/thin.rb +++ b/lib/rack/handler/thin.rb @@ -32,7 +32,22 @@ def self.valid_options } end end + end +end - register :thin, ::Rack::Handler::Thin +# rackup was removed in Rack 3, it is now a separate gem +if Object.const_defined?(:Rackup) && ::Rackup.const_defined?(:Handler) + module Rackup + module Handler + module Thin + class << ::Rack::Handler::Thin + end + end + + register :thin, ::Rackup::Handler::Thin + end end +else + do_register = Object.const_defined?(:Rack) && ::Rack.release < '3' + ::Rack::Handler.register(:thin, ::Rack::Handler::Thin) if do_register end From f513adb94ccb4e8a65b442dac9e78ccf7fb6ffaa Mon Sep 17 00:00:00 2001 From: Andrea Lorenzetti Date: Thu, 6 Feb 2025 13:06:28 +0100 Subject: [PATCH 2/3] Support rack 3.x and rackup * Split classes Rack/Rackup::Handler::Thin * Updated CI to run on rack 1/2/3 --- .github/workflows/test.yml | 19 +++++---------- lib/rack/handler/thin.rb | 48 ++++---------------------------------- lib/rackup/handler/thin.rb | 13 +++++++++++ lib/thin/rackup/handler.rb | 31 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 57 deletions(-) create mode 100644 lib/rackup/handler/thin.rb create mode 100644 lib/thin/rackup/handler.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87af470e..85a54901 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,9 @@ jobs: - 3.4 gemfile: + - gems/rack-v1.rb - gems/rack-v2.rb + - gems/rack-v3.rb include: - experimental: false @@ -48,25 +50,16 @@ jobs: os: ubuntu ruby: head gemfile: gems/rack-v2.rb - - experimental: true - os: ubuntu - ruby: 2.7 - gemfile: gems/rack-v1.rb - - experimental: true - os: ubuntu - ruby: 3.4 - gemfile: gems/rack-v2.rb - - experimental: true - os: ubuntu - ruby: 3.4 - gemfile: gems/rack-v3.rb - experimental: true os: ubuntu ruby: 3.4 gemfile: gems/rack-head.rb + exclude: + - { ruby: 3.3, gemfile: gems/rack-v1.rb } + - { ruby: 3.4, gemfile: gems/rack-v1.rb } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: diff --git a/lib/rack/handler/thin.rb b/lib/rack/handler/thin.rb index 24698cb9..0f374907 100644 --- a/lib/rack/handler/thin.rb +++ b/lib/rack/handler/thin.rb @@ -1,53 +1,13 @@ # frozen_string_literal: true -require "thin" -require "thin/server" -require "thin/logging" -require "thin/backends/tcp_server" +require 'rack/handler' +require_relative '../../thin/rackup/handler' module Rack module Handler - class Thin - def self.run(app, **options) - environment = ENV['RACK_ENV'] || 'development' - default_host = environment == 'development' ? 'localhost' : '0.0.0.0' - - host = options.delete(:Host) || default_host - port = options.delete(:Port) || 8080 - args = [host, port, app, options] - - server = ::Thin::Server.new(*args) - yield server if block_given? - - server.start - end - - def self.valid_options - environment = ENV['RACK_ENV'] || 'development' - default_host = environment == 'development' ? 'localhost' : '0.0.0.0' - - { - "Host=HOST" => "Hostname to listen on (default: #{default_host})", - "Port=PORT" => "Port to listen on (default: 8080)", - } - end + class Thin < ::Thin::Rackup::Handler end - end -end -# rackup was removed in Rack 3, it is now a separate gem -if Object.const_defined?(:Rackup) && ::Rackup.const_defined?(:Handler) - module Rackup - module Handler - module Thin - class << ::Rack::Handler::Thin - end - end - - register :thin, ::Rackup::Handler::Thin - end + register :thin, Thin.to_s end -else - do_register = Object.const_defined?(:Rack) && ::Rack.release < '3' - ::Rack::Handler.register(:thin, ::Rack::Handler::Thin) if do_register end diff --git a/lib/rackup/handler/thin.rb b/lib/rackup/handler/thin.rb new file mode 100644 index 00000000..e3d7abb1 --- /dev/null +++ b/lib/rackup/handler/thin.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'rackup/handler' +require_relative '../../thin/rackup/handler' + +module Rackup + module Handler + class Thin < ::Thin::Rackup::Handler + end + + register :thin, Thin + end +end diff --git a/lib/thin/rackup/handler.rb b/lib/thin/rackup/handler.rb new file mode 100644 index 00000000..b66e6ba2 --- /dev/null +++ b/lib/thin/rackup/handler.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Thin + module Rackup + class Handler + def self.run(app, **options) + environment = ENV['RACK_ENV'] || 'development' + default_host = environment == 'development' ? 'localhost' : '0.0.0.0' + + host = options.delete(:Host) || default_host + port = options.delete(:Port) || 8080 + args = [host, port, app, options] + + server = ::Thin::Server.new(*args) + yield server if block_given? + + server.start + end + + def self.valid_options + environment = ENV['RACK_ENV'] || 'development' + default_host = environment == 'development' ? 'localhost' : '0.0.0.0' + + { + "Host=HOST" => "Hostname to listen on (default: #{default_host})", + "Port=PORT" => "Port to listen on (default: 8080)", + } + end + end + end +end From 18843afa28bc5f03d957f238d41767837ea2dbe6 Mon Sep 17 00:00:00 2001 From: Andrea Lorenzetti Date: Fri, 7 Feb 2025 15:07:43 +0100 Subject: [PATCH 3/3] Support rack 3.x and rackup * fixed CI: ruby 3.0 means latest 3.x release while "3.0" means latest 3.0.x release * added CI build for macos with rack v3 * added CI build for ruby: head with rack v3 --- .github/workflows/test.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 85a54901..452c3e57 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: ruby: - 2.6 - 2.7 - - 3.0 + - "3.0" - 3.1 - 3.2 - 3.3 @@ -46,10 +46,18 @@ jobs: os: macos ruby: 3.4 gemfile: gems/rack-v2.rb + - experimental: false + os: macos + ruby: 3.4 + gemfile: gems/rack-v3.rb - experimental: true os: ubuntu ruby: head gemfile: gems/rack-v2.rb + - experimental: true + os: ubuntu + ruby: head + gemfile: gems/rack-v3.rb - experimental: true os: ubuntu ruby: 3.4