class ActionDispatch::Static - actionpack-4.2.4 Documentation

# class ActionDispatch::Static

This middleware will attempt to return the contents of a file's body from disk in the response. If a file is not found on disk, the request will be delegated to the application stack. This middleware is commonly initialized to serve assets from a server's `public/` directory.

This middleware verifies the path to ensure that only files living in the root directory can be rendered. A request cannot produce a directory traversal using this middleware. Only 'GET' and 'HEAD' requests will result in a file being returned.

### Public Class Methods

new(app, path, cache_control=nil) click to toggle source

    # File lib/action_dispatch/middleware/static.rb, line 101
    def initialize(app, path, cache_control=nil)
      @app = app
      @file_handler = FileHandler.new(path, cache_control)
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/action_dispatch/middleware/static.rb, line 106
    def call(env)
      case env['REQUEST_METHOD']
      when 'GET', 'HEAD'
        path = env['PATH_INFO'].chomp('/')
        if match = @file_handler.match?(path)
          env["PATH_INFO"] = match
          return @file_handler.call(env)
        end
      end

      @app.call(env)
    end