Sha256: 451db064cce3750be6951d118539571e01bb58e6f4e4c40a904143f7fa7eefdc

Contents?: true

Size: 904 Bytes

Versions: 2

Compression:

Stored size: 904 Bytes

Contents

require 'time'
require 'rack/utils'
require 'rack/mime'

module Conjur
  module WebServer
    class Home
      F = ::File
      
      def initialize(root)
        @root = root
      end
      
      # From Rack::File
      def call(env)
        path = File.expand_path("index.html", @root)

        if env["REQUEST_METHOD"] == "OPTIONS"
                return [200, {'Allow' => ALLOW_HEADER, 'Content-Length' => '0'}, []]
        end
        last_modified = F.mtime(path).httpdate
        return [304, {}, []] if env['HTTP_IF_MODIFIED_SINCE'] == last_modified

        size = F.size?(path) || Rack::Utils.bytesize(F.read(path))
  
        headers = { 
          "Last-Modified"  => last_modified,
          "Content-Type"   => "text/html",
          "Content-Length" => size.to_s
        }
  
        [ 200, headers, env["REQUEST_METHOD"] == "HEAD" ? [] : [ F.read(path) ] ]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conjur-asset-ui-api-1.1.1 lib/conjur/webserver/home.rb
conjur-asset-ui-api-1.1.0 lib/conjur/webserver/home.rb