1 # -*- encoding: binary -*-
9 # Unicorn module containing all of the classes (include C extensions) for
10 # running a Unicorn web server. It contains a minimalist HTTP server with just
11 # enough functionality to service web application requests fast as possible.
14 # \Unicorn exposes very little of an user-visible API and most of its
15 # internals are subject to change. \Unicorn is designed to host Rack
16 # applications, so applications should be written against the Rack SPEC
17 # and not \Unicorn internals.
20 # Raised inside TeeInput when a client closes the socket inside the
21 # application dispatch. This is always raised with an empty backtrace
22 # since there is nothing in the application stack that is responsible
23 # for client shutdowns/disconnects. This exception is visible to Rack
24 # applications unless PrereadInput middleware is loaded.
25 class ClientShutdown < EOFError
29 def self.run(app, options = {})
30 Unicorn::HttpServer.new(app, options).start.join
33 # This returns a lambda to pass in as the app, this does not "build" the
34 # app (which we defer based on the outcome of "preload_app" in the
35 # Unicorn config). The returned lambda will be called when it is
36 # time to build the app.
37 def self.builder(ru, opts)
38 # allow Configurator to parse cli switches embedded in the ru file
39 Unicorn::Configurator::RACKUP.update(:file => ru, :optparse => opts)
41 # always called after config file parsing, may be called after forking
46 raw.sub!(/^__END__\n.*/, '')
47 eval("Rack::Builder.new {(#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru)
50 Object.const_get(File.basename(ru, '.rb').capitalize)
53 pp({ :inner_app => inner_app }) if $DEBUG
55 # return value, matches rackup defaults based on env
59 use Rack::CommonLogger, $stderr
60 use Rack::ShowExceptions
66 use Rack::CommonLogger, $stderr
75 # returns an array of strings representing TCP listen socket addresses
76 # and Unix domain socket paths. This is useful for use with
77 # Raindrops::Middleware under Linux: http://raindrops.bogomips.org/
78 def self.listener_names
79 Unicorn::HttpServer::LISTENERS.map do |io|
80 Unicorn::SocketHelper.sock_name(io)
86 require 'unicorn/const'
87 require 'unicorn/socket_helper'
88 require 'unicorn/stream_input'
89 require 'unicorn/tee_input'
90 require 'unicorn/http_request'
91 require 'unicorn/configurator'
92 require 'unicorn/tmpio'
93 require 'unicorn/util'
94 require 'unicorn/http_response'
95 require 'unicorn/worker'
96 require 'unicorn/http_server'