Sha256: 29bd48bae06bf779ad48f1bfa8a25a29042b09b2a30e672c10fe58b283249da7
Contents?: true
Size: 922 Bytes
Versions: 5
Compression:
Stored size: 922 Bytes
Contents
require 'time' require 'rack/utils' require 'rack/mime' require 'conjur/webserver/renderer' module Conjur module WebServer class Home def initialize(root) @root = root end # From Rack::File def call(env) path = File.expand_path(INDEX, @root) renderer = Renderer.new @root page = renderer.render File.read(path) files = renderer.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 private INDEX = 'index.html.erb'.freeze end end end
Version data entries
5 entries across 5 versions & 2 rubygems