1 # -*- encoding: binary -*-
8 # Unicorn module containing all of the classes (include C extensions) for
9 # running a Unicorn web server. It contains a minimalist HTTP server with just
10 # enough functionality to service web application requests fast as possible.
12 def self.run(app, options = {})
13 Unicorn::HttpServer.new(app, options).start.join
16 # This returns a lambda to pass in as the app, this does not "build" the
17 # app (which we defer based on the outcome of "preload_app" in the
18 # Unicorn config). The returned lambda will be called when it is
19 # time to build the app.
20 def self.builder(ru, opts)
21 # allow Configurator to parse cli switches embedded in the ru file
22 Unicorn::Configurator::RACKUP.update(:file => ru, :optparse => opts)
24 # always called after config file parsing, may be called after forking
29 raw.sub!(/^__END__\n.*/, '')
30 eval("Rack::Builder.new {(#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru)
33 Object.const_get(File.basename(ru, '.rb').capitalize)
36 pp({ :inner_app => inner_app }) if $DEBUG
38 # return value, matches rackup defaults based on env
42 use Rack::CommonLogger, $stderr
43 use Rack::ShowExceptions
49 use Rack::CommonLogger, $stderr
58 # returns an array of strings representing TCP listen socket addresses
59 # and Unix domain socket paths. This is useful for use with
60 # Raindrops::Middleware under Linux: http://raindrops.bogomips.org/
61 def self.listener_names
62 Unicorn::HttpServer::LISTENERS.map do |io|
63 Unicorn::SocketHelper.sock_name(io)
68 # raised inside TeeInput when a client closes the socket inside the
69 # application dispatch. This is always raised with an empty backtrace
70 # since there is nothing in the application stack that is responsible
71 # for client shutdowns/disconnects.
72 class Unicorn::ClientShutdown < EOFError; end
74 require 'unicorn/const'
75 require 'unicorn/socket_helper'
76 require 'unicorn/stream_input'
77 require 'unicorn/tee_input'
78 require 'unicorn/http_request'
79 require 'unicorn/configurator'
80 require 'unicorn/tmpio'
81 require 'unicorn/util'
82 require 'unicorn/http_response'
83 require 'unicorn/worker'
84 require 'unicorn/http_server'