Class: Rails::Application::DefaultMiddlewareStack

Inherits:
Object
  • Object
show all
Defined in:
railties/lib/rails/application/default_middleware_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, config, paths) ⇒ DefaultMiddlewareStack

Returns a new instance of DefaultMiddlewareStack.



6
7
8
9
10
# File 'railties/lib/rails/application/default_middleware_stack.rb', line 6

def initialize(app, config, paths)
  @app = app
  @config = config
  @paths = paths
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app



4
5
6
# File 'railties/lib/rails/application/default_middleware_stack.rb', line 4

def app
  @app
end

#configObject (readonly)

Returns the value of attribute config



4
5
6
# File 'railties/lib/rails/application/default_middleware_stack.rb', line 4

def config
  @config
end

#pathsObject (readonly)

Returns the value of attribute paths



4
5
6
# File 'railties/lib/rails/application/default_middleware_stack.rb', line 4

def paths
  @paths
end

Instance Method Details

#build_stackObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'railties/lib/rails/application/default_middleware_stack.rb', line 12

def build_stack
  ActionDispatch::MiddlewareStack.new.tap do |middleware|
    if rack_cache = load_rack_cache
      require "action_dispatch/http/rack_cache"
      middleware.use ::Rack::Cache, rack_cache
    end

    if config.force_ssl
      middleware.use ::ActionDispatch::SSL, config.ssl_options
    end

    middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header

    if config.serve_static_assets
      middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
    end

    middleware.use ::Rack::Lock unless allow_concurrency?
    middleware.use ::Rack::Runtime
    middleware.use ::Rack::MethodOverride
    middleware.use ::ActionDispatch::RequestId

    # Must come after Rack::MethodOverride to properly log overridden methods
    middleware.use ::Rails::Rack::Logger, config.log_tags
    middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
    middleware.use ::ActionDispatch::DebugExceptions, app
    middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies

    unless config.cache_classes
      middleware.use ::ActionDispatch::Reloader, lambda { reload_dependencies? }
    end

    middleware.use ::ActionDispatch::Callbacks
    middleware.use ::ActionDispatch::Cookies

    if config.session_store
      if config.force_ssl && !config.session_options.key?(:secure)
        config.session_options[:secure] = true
      end
      middleware.use config.session_store, config.session_options
      middleware.use ::ActionDispatch::Flash
    end

    middleware.use ::ActionDispatch::ParamsParser
    middleware.use ::Rack::Head
    middleware.use ::Rack::ConditionalGet
    middleware.use ::Rack::ETag, "no-cache"
  end
end