From 52d4f8df0ec4d669b99810836bf813f1a0cff450 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Fri, 23 Nov 2007 17:39:24 -0800 Subject: [PATCH] a little refactoring --- lib/sinatra.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index 1b23d39..9cb1c47 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -122,16 +122,22 @@ module Sinatra Sinatra.mime_types[ext] || config[:default_static_mime_type] end - def call(env) - request = Rack::Request.new(env) - - path = Sinatra.config[:root] + '/public' + request.path_info + def serve_static_file(path) + path = Sinatra.config[:root] + '/public' + path if File.file?(path) headers = { 'Content-Type' => Array(content_type_for(path)), 'Content-Length' => Array(File.size(path)) } - return [200, headers, File.read(path)] + [200, headers, File.read(path)] + end + end + + def call(env) + request = Rack::Request.new(env) + + if found = serve_static_file(request.path_info) + return found end response = Rack::Response.new -- 2.11.4.GIT