From 5985dd50a9bd72388dd5ca4886d6dffc083f87d4 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 13 Sep 2018 10:48:25 -0700 Subject: Support default_middleware configuration option This allows for the equivalent of the -N/--no-default_middleware command line option to be specified in the configuration file so it doesn't need to be specified on the command line every time unicorn is executed. It explicitly excludes the use of -N/--no-default_middleware as an embedded configuration option in the rackup file, by ignoring the options after ARGV is parsed. In order to allow the configuration method to work, have the lambda that Unicorn.builder returns accept two arguments. Technically, only one argument is needed for the HttpServer instance, but I'm guessing if the lambda accepts a single argument, we expect that to be a rack application instead of a lambda that returns a rack application. The command line option option to disable default middleware will take precedence over the unicorn configuration file option if both are present. For backwards compatibility, if the lambda passed to HttpServer accepts 0 arguments, then call it without arguments. [ew: fix precedence for arity checking in build_app! configurator: ensure -N is respected when set in command-line] --- lib/unicorn.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'lib/unicorn.rb') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index b6dae36..5f2134d 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -45,12 +45,8 @@ module Unicorn abort "rack and Rack::Builder must be available for processing #{ru}" end - # Op is going to get cleared before the returned lambda is called, so - # save this value so that it's still there when we need it: - no_default_middleware = op[:no_default_middleware] - # always called after config file parsing, may be called after forking - lambda do || + lambda do |_, server| inner_app = case ru when /\.ru$/ raw = File.read(ru) @@ -66,7 +62,7 @@ module Unicorn pp({ :inner_app => inner_app }) end - return inner_app if no_default_middleware + return inner_app unless server.default_middleware middleware = { # order matters ContentLength: nil, -- cgit v1.2.3-24-ge0c7