From 7ab87c34d4c96454f32a2772849d54cd9173b346 Mon Sep 17 00:00:00 2001 From: James Dean Shepherd Date: Wed, 11 Oct 2023 13:22:01 +0100 Subject: [PATCH] Fix usage of deprecated Rack::File in Rack 3.0 (#896) Just a quick change to replace usage of Rack::File with Rack::Files, since this has been deprecated in Rack 3.0 and will be removed in Rack 3.1 (see https://github.com/rack/rack/blob/3-0-stable/lib/rack/file.rb). Kept backward compatibility with older Rack versions by checking for the existence of Rack::Files before instantiating it, falling back to Rack::File. --- lib/apipie/static_dispatcher.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/apipie/static_dispatcher.rb b/lib/apipie/static_dispatcher.rb index e822419c..357c168d 100644 --- a/lib/apipie/static_dispatcher.rb +++ b/lib/apipie/static_dispatcher.rb @@ -4,7 +4,13 @@ class FileHandler def initialize(root) @root = root.chomp('/') @compiled_root = /^#{Regexp.escape(root)}/ - @file_server = ::Rack::File.new(@root) + @file_server = if defined?(::Rack::Files) + ::Rack::Files.new(@root) + else + # Deprecated in Rack 3.0, kept + # for backward compatibility + ::Rack::File.new(@root) + end end def match?(path)