class Bullet::Rack

def call(env)

def call(env)
  return @app.call(env) unless Bullet.enable?
  Bullet.start_request
  status, headers, response = @app.call(env)
  response_body = nil
  if Bullet.notification? || Bullet.always_append_html_body
    request = ::Rack::Request.new(env)
    if Bullet.inject_into_page? && !skip_html_injection?(request) && !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
      if html_request?(headers, response)
        response_body = response_body(response)
        with_security_policy_nonce(headers) do |nonce|
          response_body = append_to_html_body(response_body, footer_note(nonce)) if Bullet.add_footer
          response_body = append_to_html_body(response_body, Bullet.gather_inline_notifications)
          if Bullet.add_footer && !Bullet.skip_http_headers
            response_body = append_to_html_body(response_body, xhr_script(nonce))
          end
        end
        headers['Content-Length'] = response_body.bytesize.to_s
      elsif !Bullet.skip_http_headers
        set_header(headers, 'X-bullet-footer-text', Bullet.footer_info.uniq) if Bullet.add_footer
        set_header(headers, 'X-bullet-console-text', Bullet.text_notifications) if Bullet.console_enabled?
      end
    end
    Bullet.perform_out_of_channel_notifications(env)
  end
  [status, headers, response_body ? [response_body] : response]
ensure
  Bullet.end_request
end