class ICFS::Demo::Static

Serve static files - Rack middleware

@deprecated This is a horrible implementation, DO NOT USE

for anything other than testing.

Public Class Methods

new(app, stat) click to toggle source

New instance

@param stat [Hash] maps path to Hash with :path and :mime @param app [Object] the next rack app

# File lib/icfs/demo/static.rb, line 35
def initialize(app, stat)
  @stat = stat
  @app = app
end

Public Instance Methods

call(env) click to toggle source

Process requests

# 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