class Conjur::WebServer::Home

Constants

INDEX

Public Class Methods

new(root) click to toggle source
# File lib/conjur/webserver/home.rb, line 10
def initialize(root)
  @root = root
end

Public Instance Methods

call(env) click to toggle source

From Rack::File

# File lib/conjur/webserver/home.rb, line 15
def call(env)
  path = File.expand_path(INDEX, @root)
  renderer = Renderer.new @root

  page = File.read(path)
  files = [path]

  last_modified = files.map(&File.method(:mtime)).max.httpdate

  return [304, {}, []] if env['HTTP_IF_MODIFIED_SINCE'] == last_modified

  size = Rack::Utils.bytesize(page)

  headers = {
    "Last-Modified"  => last_modified,
    "Content-Type"   => "text/html",
    "Content-Length" => size.to_s
  }

  [200, headers, env["REQUEST_METHOD"] == "HEAD" ? [] : [page]]
end