Class: SecurityTxt::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/securitytxt/middleware.rb

Overview

Rack Middleware that generates a respond.txt

Instance Method Summary collapse

Constructor Details

#initialize(app, sections = {}) ⇒ Middleware

Returns a new instance of Middleware.



4
5
6
7
# File 'lib/securitytxt/middleware.rb', line 4

def initialize(app, sections = {})
  @app = app
  @sections = sections
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# 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