unicorn-heroku-wait 4.8.0.1.g0ed2.dirty
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.CHANGELOG.old +25 -0
- data/.document +29 -0
- data/.gitignore +25 -0
- data/.mailmap +26 -0
- data/.manifest +166 -0
- data/.wrongdoc.yml +10 -0
- data/Application_Timeouts +77 -0
- data/CONTRIBUTORS +35 -0
- data/COPYING +674 -0
- data/ChangeLog +4861 -0
- data/DESIGN +97 -0
- data/Documentation/.gitignore +5 -0
- data/Documentation/GNUmakefile +30 -0
- data/Documentation/unicorn.1.txt +178 -0
- data/Documentation/unicorn_rails.1.txt +175 -0
- data/FAQ +53 -0
- data/GIT-VERSION-FILE +1 -0
- data/GIT-VERSION-GEN +39 -0
- data/GNUmakefile +267 -0
- data/HACKING +134 -0
- data/ISSUES +36 -0
- data/KNOWN_ISSUES +79 -0
- data/LATEST +28 -0
- data/LICENSE +67 -0
- data/Links +56 -0
- data/NEWS +2067 -0
- data/PHILOSOPHY +145 -0
- data/README +150 -0
- data/Rakefile +60 -0
- data/SIGNALS +123 -0
- data/Sandbox +103 -0
- data/TODO +5 -0
- data/TUNING +98 -0
- data/bin/unicorn +126 -0
- data/bin/unicorn_rails +209 -0
- data/examples/big_app_gc.rb +2 -0
- data/examples/echo.ru +27 -0
- data/examples/git.ru +13 -0
- data/examples/init.sh +74 -0
- data/examples/logger_mp_safe.rb +25 -0
- data/examples/logrotate.conf +29 -0
- data/examples/nginx.conf +156 -0
- data/examples/unicorn.conf.minimal.rb +13 -0
- data/examples/unicorn.conf.rb +102 -0
- data/ext/unicorn_http/CFLAGS +13 -0
- data/ext/unicorn_http/c_util.h +124 -0
- data/ext/unicorn_http/common_field_optimization.h +111 -0
- data/ext/unicorn_http/ext_help.h +82 -0
- data/ext/unicorn_http/extconf.rb +10 -0
- data/ext/unicorn_http/global_variables.h +97 -0
- data/ext/unicorn_http/httpdate.c +78 -0
- data/ext/unicorn_http/unicorn_http.c +4031 -0
- data/ext/unicorn_http/unicorn_http.rl +1036 -0
- data/ext/unicorn_http/unicorn_http_common.rl +76 -0
- data/lib/unicorn/app/exec_cgi.rb +154 -0
- data/lib/unicorn/app/inetd.rb +109 -0
- data/lib/unicorn/app/old_rails/static.rb +59 -0
- data/lib/unicorn/app/old_rails.rb +35 -0
- data/lib/unicorn/cgi_wrapper.rb +147 -0
- data/lib/unicorn/configurator.rb +679 -0
- data/lib/unicorn/const.rb +44 -0
- data/lib/unicorn/http_request.rb +122 -0
- data/lib/unicorn/http_response.rb +75 -0
- data/lib/unicorn/http_server.rb +803 -0
- data/lib/unicorn/launcher.rb +62 -0
- data/lib/unicorn/oob_gc.rb +71 -0
- data/lib/unicorn/preread_input.rb +33 -0
- data/lib/unicorn/socket_helper.rb +231 -0
- data/lib/unicorn/ssl_client.rb +11 -0
- data/lib/unicorn/ssl_configurator.rb +104 -0
- data/lib/unicorn/ssl_server.rb +42 -0
- data/lib/unicorn/stream_input.rb +146 -0
- data/lib/unicorn/tee_input.rb +126 -0
- data/lib/unicorn/tmpio.rb +29 -0
- data/lib/unicorn/util.rb +89 -0
- data/lib/unicorn/version.rb +1 -0
- data/lib/unicorn/worker.rb +152 -0
- data/lib/unicorn.rb +118 -0
- data/local.mk.sample +59 -0
- data/man/man1/unicorn.1 +211 -0
- data/man/man1/unicorn_rails.1 +210 -0
- data/script/isolate_for_tests +32 -0
- data/setup.rb +1586 -0
- data/t/.gitignore +5 -0
- data/t/GNUmakefile +82 -0
- data/t/README +42 -0
- data/t/bin/content-md5-put +36 -0
- data/t/bin/sha1sum.rb +17 -0
- data/t/bin/unused_listen +40 -0
- data/t/broken-app.ru +12 -0
- data/t/detach.ru +11 -0
- data/t/env.ru +3 -0
- data/t/fails-rack-lint.ru +5 -0
- data/t/heartbeat-timeout.ru +12 -0
- data/t/hijack.ru +42 -0
- data/t/listener_names.ru +4 -0
- data/t/my-tap-lib.sh +201 -0
- data/t/oob_gc.ru +20 -0
- data/t/oob_gc_path.ru +20 -0
- data/t/pid.ru +3 -0
- data/t/preread_input.ru +17 -0
- data/t/rack-input-tests.ru +21 -0
- data/t/sslgen.sh +71 -0
- data/t/t0000-http-basic.sh +50 -0
- data/t/t0001-reload-bad-config.sh +53 -0
- data/t/t0002-config-conflict.sh +49 -0
- data/t/t0002-parser-error.sh +94 -0
- data/t/t0003-working_directory.sh +51 -0
- data/t/t0004-heartbeat-timeout.sh +69 -0
- data/t/t0004-working_directory_broken.sh +24 -0
- data/t/t0005-working_directory_app.rb.sh +40 -0
- data/t/t0006-reopen-logs.sh +83 -0
- data/t/t0006.ru +13 -0
- data/t/t0007-working_directory_no_embed_cli.sh +44 -0
- data/t/t0008-back_out_of_upgrade.sh +110 -0
- data/t/t0009-broken-app.sh +56 -0
- data/t/t0009-winch_ttin.sh +59 -0
- data/t/t0010-reap-logging.sh +55 -0
- data/t/t0011-active-unix-socket.sh +79 -0
- data/t/t0012-reload-empty-config.sh +85 -0
- data/t/t0013-rewindable-input-false.sh +24 -0
- data/t/t0013.ru +12 -0
- data/t/t0014-rewindable-input-true.sh +24 -0
- data/t/t0014.ru +12 -0
- data/t/t0015-configurator-internals.sh +25 -0
- data/t/t0016-trust-x-forwarded-false.sh +30 -0
- data/t/t0017-trust-x-forwarded-true.sh +30 -0
- data/t/t0018-write-on-close.sh +23 -0
- data/t/t0019-max_header_len.sh +49 -0
- data/t/t0020-at_exit-handler.sh +49 -0
- data/t/t0021-process_detach.sh +29 -0
- data/t/t0022-listener_names-preload_app.sh +32 -0
- data/t/t0100-rack-input-tests.sh +124 -0
- data/t/t0116-client_body_buffer_size.sh +80 -0
- data/t/t0116.ru +16 -0
- data/t/t0200-rack-hijack.sh +27 -0
- data/t/t0300-no-default-middleware.sh +20 -0
- data/t/t0600-https-server-basic.sh +48 -0
- data/t/t9000-preread-input.sh +48 -0
- data/t/t9001-oob_gc.sh +47 -0
- data/t/t9002-oob_gc-path.sh +75 -0
- data/t/test-lib.sh +128 -0
- data/t/write-on-close.ru +11 -0
- data/test/aggregate.rb +15 -0
- data/test/benchmark/README +50 -0
- data/test/benchmark/dd.ru +18 -0
- data/test/benchmark/stack.ru +8 -0
- data/test/exec/README +5 -0
- data/test/exec/test_exec.rb +1047 -0
- data/test/test_helper.rb +297 -0
- data/test/unit/test_configurator.rb +175 -0
- data/test/unit/test_droplet.rb +28 -0
- data/test/unit/test_http_parser.rb +854 -0
- data/test/unit/test_http_parser_ng.rb +731 -0
- data/test/unit/test_http_parser_xftrust.rb +38 -0
- data/test/unit/test_request.rb +182 -0
- data/test/unit/test_response.rb +99 -0
- data/test/unit/test_server.rb +268 -0
- data/test/unit/test_signals.rb +188 -0
- data/test/unit/test_sni_hostnames.rb +47 -0
- data/test/unit/test_socket_helper.rb +197 -0
- data/test/unit/test_stream_input.rb +203 -0
- data/test/unit/test_tee_input.rb +294 -0
- data/test/unit/test_upload.rb +306 -0
- data/test/unit/test_util.rb +105 -0
- data/unicorn.gemspec +44 -0
- metadata +328 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
|
3
|
+
# :enddoc:
|
4
|
+
# Frequently used constants when constructing requests or responses.
|
5
|
+
# Many times the constant just refers to a string with the same
|
6
|
+
# contents. Using these constants gave about a 3% to 10% performance
|
7
|
+
# improvement over using the strings directly. Symbols did not really
|
8
|
+
# improve things much compared to constants.
|
9
|
+
module Unicorn::Const
|
10
|
+
# default TCP listen host address (0.0.0.0, all interfaces)
|
11
|
+
DEFAULT_HOST = "0.0.0.0"
|
12
|
+
|
13
|
+
# default TCP listen port (8080)
|
14
|
+
DEFAULT_PORT = 8080
|
15
|
+
|
16
|
+
# default TCP listen address and port (0.0.0.0:8080)
|
17
|
+
DEFAULT_LISTEN = "#{DEFAULT_HOST}:#{DEFAULT_PORT}"
|
18
|
+
|
19
|
+
# The basic request body size we'll try to read at once (16 kilobytes).
|
20
|
+
CHUNK_SIZE = 16 * 1024
|
21
|
+
|
22
|
+
# Maximum request body size before it is moved out of memory and into a
|
23
|
+
# temporary file for reading (112 kilobytes). This is the default
|
24
|
+
# value of client_body_buffer_size.
|
25
|
+
MAX_BODY = 1024 * 112
|
26
|
+
|
27
|
+
# :stopdoc:
|
28
|
+
# common errors we'll send back
|
29
|
+
# (N.B. these are not used by unicorn, but we won't drop them until
|
30
|
+
# unicorn 5.x to avoid breaking Rainbows!).
|
31
|
+
ERROR_400_RESPONSE = "HTTP/1.1 400 Bad Request\r\n\r\n"
|
32
|
+
ERROR_414_RESPONSE = "HTTP/1.1 414 Request-URI Too Long\r\n\r\n"
|
33
|
+
ERROR_413_RESPONSE = "HTTP/1.1 413 Request Entity Too Large\r\n\r\n"
|
34
|
+
ERROR_500_RESPONSE = "HTTP/1.1 500 Internal Server Error\r\n\r\n"
|
35
|
+
|
36
|
+
EXPECT_100_RESPONSE = "HTTP/1.1 100 Continue\r\n\r\n"
|
37
|
+
EXPECT_100_RESPONSE_SUFFIXED = "100 Continue\r\n\r\nHTTP/1.1 "
|
38
|
+
|
39
|
+
HTTP_RESPONSE_START = ['HTTP', '/1.1 ']
|
40
|
+
HTTP_EXPECT = "HTTP_EXPECT"
|
41
|
+
|
42
|
+
# :startdoc:
|
43
|
+
end
|
44
|
+
require 'unicorn/version'
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
# :enddoc:
|
3
|
+
# no stable API here
|
4
|
+
require 'unicorn_http'
|
5
|
+
|
6
|
+
# TODO: remove redundant names
|
7
|
+
Unicorn.const_set(:HttpRequest, Unicorn::HttpParser)
|
8
|
+
class Unicorn::HttpParser
|
9
|
+
|
10
|
+
# default parameters we merge into the request env for Rack handlers
|
11
|
+
DEFAULTS = {
|
12
|
+
"rack.errors" => $stderr,
|
13
|
+
"rack.multiprocess" => true,
|
14
|
+
"rack.multithread" => false,
|
15
|
+
"rack.run_once" => false,
|
16
|
+
"rack.version" => [1, 1],
|
17
|
+
"SCRIPT_NAME" => "",
|
18
|
+
|
19
|
+
# this is not in the Rack spec, but some apps may rely on it
|
20
|
+
"SERVER_SOFTWARE" => "Unicorn #{Unicorn::Const::UNICORN_VERSION}"
|
21
|
+
}
|
22
|
+
|
23
|
+
NULL_IO = StringIO.new("")
|
24
|
+
|
25
|
+
attr_accessor :response_start_sent
|
26
|
+
|
27
|
+
# :stopdoc:
|
28
|
+
# A frozen format for this is about 15% faster
|
29
|
+
REMOTE_ADDR = 'REMOTE_ADDR'.freeze
|
30
|
+
RACK_INPUT = 'rack.input'.freeze
|
31
|
+
@@input_class = Unicorn::TeeInput
|
32
|
+
@@check_client_connection = false
|
33
|
+
|
34
|
+
def self.input_class
|
35
|
+
@@input_class
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.input_class=(klass)
|
39
|
+
@@input_class = klass
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.check_client_connection
|
43
|
+
@@check_client_connection
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.check_client_connection=(bool)
|
47
|
+
@@check_client_connection = bool
|
48
|
+
end
|
49
|
+
|
50
|
+
# :startdoc:
|
51
|
+
|
52
|
+
# Does the majority of the IO processing. It has been written in
|
53
|
+
# Ruby using about 8 different IO processing strategies.
|
54
|
+
#
|
55
|
+
# It is currently carefully constructed to make sure that it gets
|
56
|
+
# the best possible performance for the common case: GET requests
|
57
|
+
# that are fully complete after a single read(2)
|
58
|
+
#
|
59
|
+
# Anyone who thinks they can make it faster is more than welcome to
|
60
|
+
# take a crack at it.
|
61
|
+
#
|
62
|
+
# returns an environment hash suitable for Rack if successful
|
63
|
+
# This does minimal exception trapping and it is up to the caller
|
64
|
+
# to handle any socket errors (e.g. user aborted upload).
|
65
|
+
def read(socket)
|
66
|
+
clear
|
67
|
+
e = env
|
68
|
+
|
69
|
+
# From http://www.ietf.org/rfc/rfc3875:
|
70
|
+
# "Script authors should be aware that the REMOTE_ADDR and
|
71
|
+
# REMOTE_HOST meta-variables (see sections 4.1.8 and 4.1.9)
|
72
|
+
# may not identify the ultimate source of the request. They
|
73
|
+
# identify the client for the immediate request to the server;
|
74
|
+
# that client may be a proxy, gateway, or other intermediary
|
75
|
+
# acting on behalf of the actual source client."
|
76
|
+
e[REMOTE_ADDR] = socket.kgio_addr
|
77
|
+
|
78
|
+
# short circuit the common case with small GET requests first
|
79
|
+
socket.kgio_read!(16384, buf)
|
80
|
+
if parse.nil?
|
81
|
+
# Parser is not done, queue up more data to read and continue parsing
|
82
|
+
# an Exception thrown from the parser will throw us out of the loop
|
83
|
+
false until add_parse(socket.kgio_read!(16384))
|
84
|
+
end
|
85
|
+
|
86
|
+
# detect if the socket is valid by writing a partial response:
|
87
|
+
if @@check_client_connection && headers?
|
88
|
+
@response_start_sent = true
|
89
|
+
Unicorn::Const::HTTP_RESPONSE_START.each { |c| socket.write(c) }
|
90
|
+
end
|
91
|
+
|
92
|
+
e[RACK_INPUT] = 0 == content_length ?
|
93
|
+
NULL_IO : @@input_class.new(socket, self)
|
94
|
+
hijack_setup(e, socket)
|
95
|
+
e.merge!(DEFAULTS)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Rack 1.5.0 (protocol version 1.2) adds hijack request support
|
99
|
+
if ((Rack::VERSION[0] << 8) | Rack::VERSION[1]) >= 0x0102
|
100
|
+
DEFAULTS["rack.hijack?"] = true
|
101
|
+
DEFAULTS["rack.version"] = [1, 2]
|
102
|
+
|
103
|
+
RACK_HIJACK = "rack.hijack".freeze
|
104
|
+
RACK_HIJACK_IO = "rack.hijack_io".freeze
|
105
|
+
|
106
|
+
def hijacked?
|
107
|
+
env.include?(RACK_HIJACK_IO)
|
108
|
+
end
|
109
|
+
|
110
|
+
def hijack_setup(e, socket)
|
111
|
+
e[RACK_HIJACK] = proc { e[RACK_HIJACK_IO] = socket }
|
112
|
+
end
|
113
|
+
else
|
114
|
+
# old Rack, do nothing.
|
115
|
+
def hijack_setup(e, _)
|
116
|
+
end
|
117
|
+
|
118
|
+
def hijacked?
|
119
|
+
false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
# :enddoc:
|
3
|
+
# Writes a Rack response to your client using the HTTP/1.1 specification.
|
4
|
+
# You use it by simply doing:
|
5
|
+
#
|
6
|
+
# status, headers, body = rack_app.call(env)
|
7
|
+
# http_response_write(socket, status, headers, body)
|
8
|
+
#
|
9
|
+
# Most header correctness (including Content-Length and Content-Type)
|
10
|
+
# is the job of Rack, with the exception of the "Date" and "Status" header.
|
11
|
+
module Unicorn::HttpResponse
|
12
|
+
|
13
|
+
# Every standard HTTP code mapped to the appropriate message.
|
14
|
+
CODES = Rack::Utils::HTTP_STATUS_CODES.inject({}) { |hash,(code,msg)|
|
15
|
+
hash[code] = "#{code} #{msg}"
|
16
|
+
hash
|
17
|
+
}
|
18
|
+
CRLF = "\r\n"
|
19
|
+
|
20
|
+
def err_response(code, response_start_sent)
|
21
|
+
"#{response_start_sent ? '' : 'HTTP/1.1 '}#{CODES[code]}\r\n\r\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
# writes the rack_response to socket as an HTTP response
|
25
|
+
def http_response_write(socket, status, headers, body,
|
26
|
+
response_start_sent=false)
|
27
|
+
status = CODES[status.to_i] || status
|
28
|
+
hijack = nil
|
29
|
+
|
30
|
+
http_response_start = response_start_sent ? '' : 'HTTP/1.1 '
|
31
|
+
if headers
|
32
|
+
buf = "#{http_response_start}#{status}\r\n" \
|
33
|
+
"Date: #{httpdate}\r\n" \
|
34
|
+
"Status: #{status}\r\n" \
|
35
|
+
"Connection: close\r\n"
|
36
|
+
headers.each do |key, value|
|
37
|
+
case key
|
38
|
+
when %r{\A(?:Date\z|Connection\z)}i
|
39
|
+
next
|
40
|
+
when "rack.hijack"
|
41
|
+
# this was an illegal key in Rack < 1.5, so it should be
|
42
|
+
# OK to silently discard it for those older versions
|
43
|
+
hijack = hijack_prepare(value)
|
44
|
+
else
|
45
|
+
if value =~ /\n/
|
46
|
+
# avoiding blank, key-only cookies with /\n+/
|
47
|
+
buf << value.split(/\n+/).map! { |v| "#{key}: #{v}\r\n" }.join
|
48
|
+
else
|
49
|
+
buf << "#{key}: #{value}\r\n"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
socket.write(buf << CRLF)
|
54
|
+
end
|
55
|
+
|
56
|
+
if hijack
|
57
|
+
body = nil # ensure we do not close body
|
58
|
+
hijack.call(socket)
|
59
|
+
else
|
60
|
+
body.each { |chunk| socket.write(chunk) }
|
61
|
+
end
|
62
|
+
ensure
|
63
|
+
body.respond_to?(:close) and body.close
|
64
|
+
end
|
65
|
+
|
66
|
+
# Rack 1.5.0 (protocol version 1.2) adds response hijacking support
|
67
|
+
if ((Rack::VERSION[0] << 8) | Rack::VERSION[1]) >= 0x0102
|
68
|
+
def hijack_prepare(value)
|
69
|
+
value
|
70
|
+
end
|
71
|
+
else
|
72
|
+
def hijack_prepare(_)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|