From af8c54be0a88af7e8227f156257236a10da7ffbe Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 2 May 2011 17:05:20 -0700 Subject: [PATCH] cache strings in the AST for faster comparison than include? --- actionpack/lib/action_dispatch/middleware/static.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 360c1209bb..404943d720 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -35,18 +35,15 @@ def ext end class Static - FILE_METHODS = %w(GET HEAD).freeze - def initialize(app, path, cache_control=nil) @app = app @file_handler = FileHandler.new(path, cache_control) end def call(env) - path = env['PATH_INFO'].chomp('/') - method = env['REQUEST_METHOD'] - - if FILE_METHODS.include?(method) + case env['REQUEST_METHOD'] + when 'GET', 'HEAD' + path = env['PATH_INFO'].chomp('/') if match = @file_handler.match?(path) env["PATH_INFO"] = match return @file_handler.call(env) -- GitLab