Class: Conjur::WebServer::Home

Inherits:
Object
  • Object
show all
Defined in:
lib/conjur/webserver/home.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Home

Returns a new instance of Home.



10
11
12
# File 'lib/conjur/webserver/home.rb', line 10

def initialize(root)
  @root = root
end

Instance Method Details

#call(env) ⇒ Object

From Rack::File



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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