Class: Cannon::Middleware::Files

Inherits:
Object
  • Object
show all
Includes:
PathCache
Defined in:
lib/cannon/middleware/files.rb

Instance Method Summary collapse

Methods included from PathCache

included

Constructor Details

#initialize(app) ⇒ Files

Returns a new instance of Files.



6
7
8
9
10
11
# File 'lib/cannon/middleware/files.rb', line 6

def initialize(app)
  @app = app

  self.cache = :files
  self.base_path = build_base_path
end

Instance Method Details

#run(request, response, next_proc) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cannon/middleware/files.rb', line 13

def run(request, response, next_proc)
  reload_cache if outdated_cache?

  if path_array.include? request.path
    file, content_type = *file_and_content_type("#{base_path}#{request.path}")
    response.header('Content-Type', content_type)
    response.send(file)
    response.flush
  else
    next_proc.call
  end
end