diff --git a/lib/protocol/rack/adapter.rb b/lib/protocol/rack/adapter.rb index 1fced83..28ef0bb 100644 --- a/lib/protocol/rack/adapter.rb +++ b/lib/protocol/rack/adapter.rb @@ -24,6 +24,10 @@ def self.new(app) def self.make_response(env, response) IMPLEMENTATION.make_response(env, response) end + + def self.parse_file(...) + IMPLEMENTATION.parse_file(...) + end end end end diff --git a/lib/protocol/rack/adapter/generic.rb b/lib/protocol/rack/adapter/generic.rb index 49c0f1b..b2822a9 100644 --- a/lib/protocol/rack/adapter/generic.rb +++ b/lib/protocol/rack/adapter/generic.rb @@ -17,6 +17,11 @@ def self.wrap(app) self.new(app) end + def self.parse_file(...) + # This is the old interface, which was changed in Rack 3. + ::Rack::Builder.parse_file(...).first + end + # Initialize the rack adaptor middleware. # @parameter app [Object] The rack middleware. def initialize(app) diff --git a/lib/protocol/rack/adapter/rack3.rb b/lib/protocol/rack/adapter/rack3.rb index a8e1d93..75c5761 100644 --- a/lib/protocol/rack/adapter/rack3.rb +++ b/lib/protocol/rack/adapter/rack3.rb @@ -15,6 +15,10 @@ def self.wrap(app) self.new(app) end + def self.parse_file(...) + ::Rack::Builder.parse_file(...) + end + def make_environment(request) request_path, query_string = request.path.split('?', 2) server_name, server_port = (request.authority || '').split(':', 2) diff --git a/test/protocol/rack/.adapter/config.ru b/test/protocol/rack/.adapter/config.ru new file mode 100644 index 0000000..736c90e --- /dev/null +++ b/test/protocol/rack/.adapter/config.ru @@ -0,0 +1,4 @@ + +run lambda {|env| + [200, {}, ["Hello World!"]] +} diff --git a/test/protocol/rack/adapter.rb b/test/protocol/rack/adapter.rb index 168f279..07770f6 100644 --- a/test/protocol/rack/adapter.rb +++ b/test/protocol/rack/adapter.rb @@ -9,6 +9,14 @@ require 'disable_console_context' require 'server_context' +describe Protocol::Rack::Adapter do + let(:rackup_path) {File.expand_path(".adapter/config.ru", __dir__)} + + it "can load rackup files" do + expect(subject.parse_file(rackup_path)).to be_a(Proc) + end +end + describe Protocol::Rack::Adapter::Generic do let(:adapter) {subject.new(lambda{})}