class PermanentNotFound

Constants

CONTENT
VERSION

Public Class Methods

new(app, content: CONTENT, paths: [], pattern: []) click to toggle source
# File lib/permanent_not_found.rb, line 7
def initialize(app, content: CONTENT, paths: [], pattern: [])
  @app     = app
  @content = content
  @paths   = Set.new(paths)
  @pattern = Regexp.union(pattern)
end

Public Instance Methods

call(env) click to toggle source
# File lib/permanent_not_found.rb, line 14
def call(env)
  if permanent_redirected?(env['PATH_INFO'].downcase)
    response_with_404
  else
    @app.call(env)
  end
end

Private Instance Methods

permanent_redirected?(path) click to toggle source
# File lib/permanent_not_found.rb, line 24
def permanent_redirected?(path)
  @paths.include?(path) || @pattern =~ path
end
response_with_404() click to toggle source
# File lib/permanent_not_found.rb, line 28
def response_with_404
  [404, { 'Content-Type' => 'text/html', 'Content-Length' => @content.size.to_s }, [@content]]
end