Class: TenantCheck::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/tenant_check/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



7
8
9
# File 'lib/tenant_check/rack.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tenant_check/rack.rb', line 11

def call(env)
  TenantCheck.start
  status, headers, response = @app.call(env)
  if TenantCheck.notification? && html_headers?(status, headers) && (body = response_body(response))
    TenantCheck.output_notifications
    body = append_to_html_body(body, footer_html)
    content_length = body.bytesize.to_s
    headers['Content-Length'] = content_length
    # maintains compatibility with other middlewares
    if defined?(ActionDispatch::Response::RackBody) && response.is_a?(ActionDispatch::Response::RackBody)
      ActionDispatch::Response.new(status, headers, [body]).to_a
    else
      [status, headers, [body]]
    end
  else
    [status, headers, response]
  end
ensure
  TenantCheck.end
end