about summary refs log tree commit homepage
path: root/lib/unicorn.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2018-09-13 10:48:25 -0700
committerEric Wong <e@80x24.org>2018-09-21 00:29:11 +0000
commit5985dd50a9bd72388dd5ca4886d6dffc083f87d4 (patch)
treea62dec60cfbfa8d0641207352f89b0538eef0319 /lib/unicorn.rb
parentc93a392385e7fe1ca3bf86cabe04f7591cef1a58 (diff)
downloadunicorn-5985dd50a9bd72388dd5ca4886d6dffc083f87d4.tar.gz
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]
Diffstat (limited to 'lib/unicorn.rb')
-rw-r--r--lib/unicorn.rb8
1 files changed, 2 insertions, 6 deletions
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,