Skip to content

Commit

Permalink
Support rack 3.x and rackup (#435)
Browse files Browse the repository at this point in the history
* Fixed registration of Thin with `rack`/`rackup`.

* Updated CI to run on rack 1/2/3.
  • Loading branch information
and9000 authored Feb 7, 2025
1 parent dac0260 commit dbf793a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 40 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,44 @@ jobs:
ruby:
- 2.6
- 2.7
- 3.0
- "3.0"
- 3.1
- 3.2
- 3.3
- 3.4

gemfile:
- gems/rack-v1.rb
- gems/rack-v2.rb
- gems/rack-v3.rb

include:
- experimental: false
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: 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
ruby: head
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:
Expand Down
1 change: 1 addition & 0 deletions gems/rack-head.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
eval_gemfile "../Gemfile"

gem 'rack', github: 'rack/rack'
gem 'rackup'
1 change: 1 addition & 0 deletions gems/rack-v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
eval_gemfile "../Gemfile"

gem 'rack', "~> 3.0"
gem 'rackup'
33 changes: 4 additions & 29 deletions lib/rack/handler/thin.rb
Original file line number Diff line number Diff line change
@@ -1,38 +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

register :thin, ::Rack::Handler::Thin
register :thin, Thin.to_s
end
end
13 changes: 13 additions & 0 deletions lib/rackup/handler/thin.rb
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions lib/thin/rackup/handler.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dbf793a

Please sign in to comment.