class SecurityTxt::Middleware

Rack Middleware that generates a respond.txt

Public Class Methods

new(app, sections = {}) click to toggle source
# File lib/securitytxt/middleware.rb, line 4
def initialize(app, sections = {})
  @app = app
  @sections = sections
end

Public Instance Methods

call(env) click to toggle source
# File lib/securitytxt/middleware.rb, line 9
def call(env)
  req = Rack::Request.new(env)

  sections = @sections
  sections = @sections.call if @sections.respond_to?(:call)
  if req.path == '/.well-known/security.txt' && !sections.empty?
    return Rack::Response.new(Generator.new(sections).generate, 200,
                              'Content-Type' => 'text/plain')
  end
  @app.call(env)
end