Sha256: 37075195a48c0c1db1966ed1bdff8c0215cb1eb3ce93e1e12a426cef1ab66035

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

module RooOnRails
  module Railties
    class HTTP < Rails::Railtie
      initializer 'roo_on_rails.http' do |app|
        Rails.logger.debug '[roo_on_rails.http] loading'

        require 'rack/timeout/base'
        require 'rack/ssl-enforcer'
        require 'roo_on_rails/rack/safe_timeouts'

        ::Rack::Timeout::Logger.level = ::Logger::WARN

        app.config.middleware.insert_before(
          ::Rack::Runtime,
          ::Rack::Timeout,
          service_timeout: ENV.fetch('RACK_SERVICE_TIMEOUT', 15).to_i,
          wait_timeout: ENV.fetch('RACK_WAIT_TIMEOUT', 30).to_i
        )

        if Rails::VERSION::MAJOR < 4
          middleware_to_insert_before = ::ActionDispatch::Cookies
        else
          middleware_to_insert_before = ::Rack::Head
        end

        # This needs to be inserted low in the stack, before Rails returns the
        # thread-current connection to the pool.
        if defined?(ActiveRecord)
          app.config.middleware.insert_before(
            middleware_to_insert_before,
            RooOnRails::Rack::SafeTimeouts
          )
        end

        if ENV.fetch('ROO_ON_RAILS_RACK_DEFLATE', 'YES').to_s =~ /\A(YES|TRUE|ON|1)\Z/i
          app.config.middleware.use ::Rack::Deflater
        end

        # Don't use SslEnforcer in test environment as it breaks Capybara
        unless Rails.env.test? ||
               ENV.fetch('ROO_ON_RAILS_DISABLE_SSL_ENFORCEMENT', '') =~ /\A(YES|TRUE|ON|1)\Z/i
          app.config.middleware.insert_before(
            middleware_to_insert_before,
            ::Rack::SslEnforcer
          )
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roo_on_rails-2.1.2 lib/roo_on_rails/railties/http.rb
roo_on_rails-2.1.0 lib/roo_on_rails/railties/http.rb