Sha256: 90c8712578e2815da3e4a6d781630321d8339b09d56838ac0677501c66198fe1
Contents?: true
Size: 1.13 KB
Versions: 14
Compression:
Stored size: 1.13 KB
Contents
module Rack # Rack::FileNotFound rescues file-not-found exceptions # (raised when action template files are not found) and returns an # HTTP 404 error response. class FileNotFound def initialize(app, options = {}) @_app = app path = options[:path] @_body = path ? ( ::File.file?(path) ? ::File.read(path) : template('could not find specified FileNotFound error document') ) : template end def call(env) code, headers, body = @_app.call(env) rescue Kiss::FileNotFoundError => e [ 404, { "Content-Type" => "text/html", "Content-Length" => @_body.content_length.to_s }, @_body ] end def template(error = nil) <<EOT <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="robots" content="NONE,NOARCHIVE" /> <title>File Not Found</title> </head> <body> <h1>404 File Not Found</h1> #{error ? "<p>Additionally, #{error}.</p>" : ''} </body> </html> EOT end end end
Version data entries
14 entries across 14 versions & 1 rubygems