lib/roda/plugins/public.rb in roda-3.35.0 vs lib/roda/plugins/public.rb in roda-3.36.0
- old
+ new
@@ -58,25 +58,11 @@
end
module RequestMethods
# Serve files from the public directory if the file exists and this is a GET request.
def public
- if is_get?
- path = PARSER.unescape(real_remaining_path)
- return if path.include?("\0")
-
- roda_opts = roda_class.opts
- server = roda_opts[:public_server]
- path = ::File.join(server.root, *public_path_segments(path))
-
- public_serve_compressed(server, path, '.br', 'br') if roda_opts[:public_brotli]
- public_serve_compressed(server, path, '.gz', 'gzip') if roda_opts[:public_gzip]
-
- if public_file_readable?(path)
- halt public_serve(server, path)
- end
- end
+ public_serve_with(roda_class.opts[:public_server])
end
private
# Return an array of segments for the given path, handling ..
@@ -97,9 +83,25 @@
::File.file?(path) && ::File.readable?(path)
rescue SystemCallError
# :nocov:
false
# :nocov:
+ end
+
+ def public_serve_with(server)
+ return unless is_get?
+ path = PARSER.unescape(real_remaining_path)
+ return if path.include?("\0")
+
+ roda_opts = roda_class.opts
+ path = ::File.join(server.root, *public_path_segments(path))
+
+ public_serve_compressed(server, path, '.br', 'br') if roda_opts[:public_brotli]
+ public_serve_compressed(server, path, '.gz', 'gzip') if roda_opts[:public_gzip]
+
+ if public_file_readable?(path)
+ halt public_serve(server, path)
+ end
end
def public_serve_compressed(server, path, suffix, encoding)
if env['HTTP_ACCEPT_ENCODING'] =~ /\b#{encoding}\b/
compressed_path = path + suffix