Class: ICFS::Demo::Static Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/icfs/demo/static.rb

Overview

Deprecated.

This is a horrible implementation, DO NOT USE for anything other than testing.

Serve static files - Rack middleware

Instance Method Summary collapse

Constructor Details

#initialize(app, stat) ⇒ Static

New instance

Parameters:

  • stat (Hash)

    maps path to Hash with :path and :mime

  • app (Object)

    the next rack app



35
36
37
38
# File 'lib/icfs/demo/static.rb', line 35

def initialize(app, stat)
  @stat = stat
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Process requests



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/icfs/demo/static.rb', line 41

def call(env)

  # see if we have a static file to serve
  st = @stat[env['PATH_INFO']]
  if st
    cont = File.read(st['path'])
    head = {
      'Content-Type' => st['mime'],
      'Content-Length' => cont.bytesize.to_s
    }
    return [200, head, [cont]]
  end

  return @app.call(env)

end