Module: Flame::Dispatcher::Static
- Included in:
- Flame::Dispatcher
- Defined in:
- lib/flame/static.rb
Overview
Module for working with static files
Instance Method Summary collapse
- #return_static(file) ⇒ Object
- #static_cached?(file_time) ⇒ Boolean
-
#try_static(dir = config[:public_dir]) ⇒ Object
Find static files and try return it.
Instance Method Details
#return_static(file) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/flame/static.rb', line 17 def return_static(file) file_time = File.mtime(file) halt 304 if static_cached?(file_time) content_type File.extname(file) response['Last-Modified'] = file_time.httpdate # 'Content-Disposition' => 'attachment;' \ # "filename=\"#{File.basename(static_file)}\"", # 'Content-Length' => File.size?(static_file).to_s halt 200, File.read(file) end |
#static_cached?(file_time) ⇒ Boolean
12 13 14 15 |
# File 'lib/flame/static.rb', line 12 def static_cached?(file_time) since = request.env['HTTP_IF_MODIFIED_SINCE'] since && Time.httpdate(since).to_i >= file_time.to_i end |
#try_static(dir = config[:public_dir]) ⇒ Object
Find static files and try return it
6 7 8 9 10 |
# File 'lib/flame/static.rb', line 6 def try_static(dir = config[:public_dir]) file = File.join(dir, URI.decode(request.path_info)) return nil unless File.exist?(file) && File.file?(file) return_static(file) end |