class Vienna::NotFound

`Vienna::NotFound` is a default endpoint not unlike `Rack::NotFound`. Initialize it with the path to a 404 page and its contents will be served. The difference is that if a 404 page doesn't exist, a default response, 'Not Found' will be served.

Examples

run Vienna::NotFound.new('public/404.html')

run Vienna::NotFound.new # Always return 'Not Found'

Public Class Methods

new(path = '') click to toggle source
# File lib/vienna.rb, line 79
def initialize(path = '')
  @path = path
end

Public Instance Methods

body() click to toggle source
# File lib/vienna.rb, line 103
def body
  [content]
end
call(env) click to toggle source
# File lib/vienna.rb, line 107
def call(env)
  [status, headers, body]
end
content() click to toggle source
# File lib/vienna.rb, line 84
def content
  File.exist?(@path) ? File.read(@path) : 'Not Found'
end
content_length() click to toggle source
# File lib/vienna.rb, line 88
def content_length
  content.length.to_s
end
headers() click to toggle source
# File lib/vienna.rb, line 96
def headers
  {
    'Content-Type' => 'text/html',
    'Content-Length' => content_length
  }
end
status() click to toggle source
# File lib/vienna.rb, line 92
def status
  404
end