Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Rack::Builder::Config, and support middleware.rackup configuring middleware based on server configuration #1720

Merged
merged 11 commits into from Jan 27, 2022

Commits on Jan 27, 2022

  1. Remove rack.multithread/rack.multiprocess/rack.run_once.

    These variables generally come too late to be useful. Removed `Rack::Lock` which depends on these variables.
    ioquatix authored and jeremyevans committed Jan 27, 2022
    Copy the full SHA
    e9e8ec3 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    fb677a0 View commit details
    Browse the repository at this point in the history
  3. Allow passing a configuration to Builder, and use it when building

    This adds Rack::Builder::Config, which stores information on the
    server's configuration, such as whether it is multithreaded or
    supports reentrancy.
    
    Middleware can use the configuration by defining a rackup method
    in addition to a new method.  If the rackup method is defined,
    it is called instead of the new method, with the configuration
    as the first argument and with the remaining arguments and block
    the same as what would be passed to new.
    
    In cases where the server's configuration indicates the middleware
    is not needed, the middleware rackup method can be just return the
    app itself.
    
    To handle the very rare case where a middleware would want to
    delegate to other middleware in certain server configurations, and
    doesn't know whether the other middleware supports the rackup
    method or not, The configuration object supports a rackup method,
    which will call rackup on the middleware if defined, or new
    otherwise.  So if middleware A wants to use external middleware B
    in a certain server configuration, middleware A's rackup method
    could be something like:
    
      def self.rackup(config, app)
        if config.multithread?
          config.rackup(MiddlewareB, app)
        else
          new(app)
        end
      end
    
    The configuration rackup method is also used internally to implement
    the builder.
    
    This readds Rack::Lock, using the rackup method, which only uses
    the Rack::Lock middleware if the configuration indicates the
    server is multithreaded.
    
    The advantage of this approach is that it doesn't require exposing
    the entire builder API to the middleware, it only exposes the
    server configuration, which is all the middleware should need to
    appropriately configure itself.
    jeremyevans committed Jan 27, 2022
    Copy the full SHA
    34efacb View commit details
    Browse the repository at this point in the history
  4. Fixup rack lint

    jeremyevans committed Jan 27, 2022
    Copy the full SHA
    59a14b5 View commit details
    Browse the repository at this point in the history
  5. Copy the full SHA
    174b412 View commit details
    Browse the repository at this point in the history
  6. Add Rack::Builder::EVAL_CONTEXT

    Avoids the need to use TOPLEVEL_BINDING.
    jeremyevans committed Jan 27, 2022
    Copy the full SHA
    64785cd View commit details
    Browse the repository at this point in the history
  7. Copy the full SHA
    ece9dc9 View commit details
    Browse the repository at this point in the history
  8. Copy the full SHA
    80f0a14 View commit details
    Browse the repository at this point in the history
  9. Don't use Rack::Lock for concurrent but not multithread configuration…

    … on Ruby 2
    
    Ruby 2 Mutex only works for multiple threads, not multiple fibers.
    
    Such apps are probably still broken at runtime unless they are
    using their own locks, but this matches the Rack 2 behavior.
    jeremyevans committed Jan 27, 2022
    Copy the full SHA
    4d3bce0 View commit details
    Browse the repository at this point in the history
  10. Copy the full SHA
    38baae6 View commit details
    Browse the repository at this point in the history
  11. Restore Rack::Lock implementation

    This correctly doesn't release the lock until after the body is
    closed. Restore the related tests as well.  Just make changes to
    avoid use of rack.multithread.
    jeremyevans committed Jan 27, 2022
    Copy the full SHA
    a8a0459 View commit details
    Browse the repository at this point in the history