Class: Phaedra::Middleware::NotFound

Inherits:
Object
  • Object
show all
Defined in:
lib/phaedra/rack_middleware/not_found.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, path, content_type = 'text/html; charset=utf-8') ⇒ NotFound

Returns a new instance of NotFound.



4
5
6
7
8
9
# File 'lib/phaedra/rack_middleware/not_found.rb', line 4

def initialize(app, path, content_type = 'text/html; charset=utf-8')
  @app = app
  @content = File.read(path)
  @length = @content.bytesize.to_s
  @content_type = content_type
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/phaedra/rack_middleware/not_found.rb', line 11

def call(env)
  response = @app.call(env)
  if response[0] == 404
    [404, {'Content-Type' => @content_type, 'Content-Length' => @length}, [@content]]
  else
    response
  end
end