thin 1.8.2 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of thin might be problematic. Click here for more details.

Files changed (108) hide show
  1. data/.gitignore +9 -0
  2. data/CHANGELOG +29 -116
  3. data/Gemfile +8 -0
  4. data/README.md +44 -78
  5. data/Rakefile +28 -18
  6. data/bin/thin +4 -4
  7. data/examples/async.ru +21 -0
  8. data/examples/thin.conf.rb +39 -0
  9. data/lib/thin/async.rb +108 -0
  10. data/lib/thin/backends/prefork.rb +44 -0
  11. data/lib/thin/backends/single_process.rb +28 -0
  12. data/lib/thin/chunked_body.rb +28 -0
  13. data/lib/thin/configurator.rb +118 -0
  14. data/lib/thin/connection.rb +246 -172
  15. data/lib/thin/listener.rb +114 -0
  16. data/lib/thin/request.rb +94 -76
  17. data/lib/thin/response.rb +112 -45
  18. data/lib/thin/runner.rb +134 -197
  19. data/lib/thin/server.rb +203 -252
  20. data/lib/thin/system.rb +49 -0
  21. data/lib/thin/version.rb +12 -27
  22. data/lib/thin.rb +2 -44
  23. data/man/index.txt +3 -0
  24. data/man/thin-conf.5.ronn +121 -0
  25. data/man/thin.1.ronn +105 -0
  26. data/site/.gitignore +2 -0
  27. data/site/README.md +21 -0
  28. data/site/Rakefile +20 -0
  29. data/site/config.ru +4 -0
  30. data/site/public/images/grid.png +0 -0
  31. data/site/public/javascripts/dd_belatedpng.js +13 -0
  32. data/site/public/javascripts/modernizr-1.6.min.js +30 -0
  33. data/site/public/man/thin-conf.5.html +220 -0
  34. data/site/public/man/thin.1.html +177 -0
  35. data/site/site/assets/javascripts/main.coffee +2 -0
  36. data/site/site/assets/stylesheets/_config.scss +55 -0
  37. data/site/site/assets/stylesheets/main.scss +24 -0
  38. data/site/site/helpers.rb +17 -0
  39. data/site/site/layouts/base.erb +55 -0
  40. data/site/site/layouts/default.erb +17 -0
  41. data/site/site/pages/about.md +5 -0
  42. data/site/site/pages/index.erb +10 -0
  43. data/site/site/partials/.gitkeep +0 -0
  44. data/test/fixtures/big.txt +1 -0
  45. data/test/fixtures/small.txt +1 -0
  46. data/test/fixtures/thin.conf.rb +15 -0
  47. data/test/integration/async_test.rb +35 -0
  48. data/test/integration/big_request_test.rb +30 -0
  49. data/test/integration/config.ru +57 -0
  50. data/test/integration/daemonize_test.rb +26 -0
  51. data/test/integration/env_test.rb +44 -0
  52. data/test/integration/error_test.rb +37 -0
  53. data/test/integration/file_sending_test.rb +24 -0
  54. data/test/integration/keep_alive_test.rb +35 -0
  55. data/test/integration/robustness_test.rb +37 -0
  56. data/test/integration/single_process_test.rb +15 -0
  57. data/test/integration/socket_family_test.rb +38 -0
  58. data/test/integration/worker_test.rb +22 -0
  59. data/test/test_helper.rb +195 -0
  60. data/test/unit/configurator_test.rb +43 -0
  61. data/test/unit/connection_test.rb +94 -0
  62. data/test/unit/listener_test.rb +74 -0
  63. data/test/unit/request_test.rb +74 -0
  64. data/test/unit/response_test.rb +90 -0
  65. data/test/unit/server_test.rb +29 -0
  66. data/test/unit/system_test.rb +17 -0
  67. data/thin.gemspec +26 -0
  68. data/v2.todo +21 -0
  69. metadata +138 -93
  70. checksums.yaml +0 -7
  71. data/example/adapter.rb +0 -32
  72. data/example/async_app.ru +0 -126
  73. data/example/async_chat.ru +0 -247
  74. data/example/async_tailer.ru +0 -100
  75. data/example/config.ru +0 -22
  76. data/example/monit_sockets +0 -20
  77. data/example/monit_unixsock +0 -20
  78. data/example/myapp.rb +0 -1
  79. data/example/ramaze.ru +0 -12
  80. data/example/thin.god +0 -80
  81. data/example/thin_solaris_smf.erb +0 -36
  82. data/example/thin_solaris_smf.readme.txt +0 -150
  83. data/example/vlad.rake +0 -72
  84. data/ext/thin_parser/common.rl +0 -59
  85. data/ext/thin_parser/ext_help.h +0 -14
  86. data/ext/thin_parser/extconf.rb +0 -6
  87. data/ext/thin_parser/parser.c +0 -1447
  88. data/ext/thin_parser/parser.h +0 -49
  89. data/ext/thin_parser/parser.rl +0 -152
  90. data/ext/thin_parser/thin.c +0 -435
  91. data/lib/rack/adapter/loader.rb +0 -75
  92. data/lib/rack/adapter/rails.rb +0 -178
  93. data/lib/rack/handler/thin.rb +0 -38
  94. data/lib/thin/backends/base.rb +0 -169
  95. data/lib/thin/backends/swiftiply_client.rb +0 -66
  96. data/lib/thin/backends/tcp_server.rb +0 -34
  97. data/lib/thin/backends/unix_server.rb +0 -56
  98. data/lib/thin/command.rb +0 -53
  99. data/lib/thin/controllers/cluster.rb +0 -178
  100. data/lib/thin/controllers/controller.rb +0 -189
  101. data/lib/thin/controllers/service.rb +0 -76
  102. data/lib/thin/controllers/service.sh.erb +0 -39
  103. data/lib/thin/daemonizing.rb +0 -199
  104. data/lib/thin/headers.rb +0 -47
  105. data/lib/thin/logging.rb +0 -174
  106. data/lib/thin/stats.html.erb +0 -216
  107. data/lib/thin/stats.rb +0 -52
  108. data/lib/thin/statuses.rb +0 -48
data/lib/thin/headers.rb DELETED
@@ -1,47 +0,0 @@
1
- module Thin
2
- # Raised when an header is not valid
3
- # and the server can not process it.
4
- class InvalidHeader < StandardError; end
5
-
6
- # Store HTTP header name-value pairs direcly to a string
7
- # and allow duplicated entries on some names.
8
- class Headers
9
- HEADER_FORMAT = "%s: %s\r\n".freeze
10
- ALLOWED_DUPLICATES = %w(set-cookie set-cookie2 warning www-authenticate).freeze
11
- CR_OR_LF = /[\r\n]/.freeze
12
-
13
- def initialize
14
- @sent = {}
15
- @out = []
16
- end
17
-
18
- # Add <tt>key: value</tt> pair to the headers.
19
- # Ignore if already sent and no duplicates are allowed
20
- # for this +key+.
21
- def []=(key, value)
22
- downcase_key = key.downcase
23
- if !@sent.has_key?(downcase_key) || ALLOWED_DUPLICATES.include?(downcase_key)
24
- @sent[downcase_key] = true
25
- value = case value
26
- when Time
27
- value.httpdate
28
- when NilClass
29
- return
30
- when CR_OR_LF
31
- raise InvalidHeader, "Header contains CR or LF"
32
- else
33
- value.to_s
34
- end
35
- @out << HEADER_FORMAT % [key, value]
36
- end
37
- end
38
-
39
- def has_key?(key)
40
- @sent[key.downcase]
41
- end
42
-
43
- def to_s
44
- @out.join
45
- end
46
- end
47
- end
data/lib/thin/logging.rb DELETED
@@ -1,174 +0,0 @@
1
- require 'logger'
2
-
3
- module Thin
4
- # To be included in classes to allow some basic logging
5
- # that can be silenced (<tt>Logging.silent=</tt>) or made
6
- # more verbose.
7
- # <tt>Logging.trace=</tt>: log all raw request and response and
8
- # messages logged with +trace+.
9
- # <tt>Logging.silent=</tt>: silence all log all log messages
10
- # altogether.
11
- module Logging
12
- # Simple formatter which only displays the message.
13
- # Taken from ActiveSupport
14
- class SimpleFormatter < Logger::Formatter
15
- def call(severity, timestamp, progname, msg)
16
- "#{timestamp} #{String === msg ? msg : msg.inspect}\n"
17
- end
18
- end
19
-
20
- @trace_logger = nil
21
-
22
- class << self
23
- attr_reader :logger
24
- attr_reader :trace_logger
25
-
26
- def trace=(enabled)
27
- if enabled
28
- @trace_logger ||= Logger.new(STDOUT)
29
- else
30
- @trace_logger = nil
31
- end
32
- end
33
-
34
- def trace?
35
- !@trace_logger.nil?
36
- end
37
-
38
- def silent=(shh)
39
- if shh
40
- @logger = nil
41
- else
42
- @logger ||= Logger.new(STDOUT)
43
- end
44
- end
45
-
46
- def silent?
47
- !@logger.nil?
48
- end
49
-
50
- def level
51
- @logger ? @logger.level : nil # or 'silent'
52
- end
53
-
54
- def level=(value)
55
- # If logging has been silenced, then re-enable logging
56
- @logger = Logger.new(STDOUT) if @logger.nil?
57
- @logger.level = value
58
- end
59
-
60
- # Allow user to specify a custom logger to use.
61
- # This object must respond to:
62
- # +level+, +level=+ and +debug+, +info+, +warn+, +error+, +fatal+
63
- def logger=(custom_logger)
64
- [ :level ,
65
- :level= ,
66
- :debug ,
67
- :info ,
68
- :warn ,
69
- :error ,
70
- :fatal ,
71
- :unknown ,
72
- ].each do |method|
73
- if not custom_logger.respond_to?(method)
74
- raise ArgumentError, "logger must respond to #{method}"
75
- end
76
- end
77
-
78
- @logger = custom_logger
79
- end
80
-
81
- def trace_logger=(custom_tracer)
82
- [ :level ,
83
- :level= ,
84
- :debug ,
85
- :info ,
86
- :warn ,
87
- :error ,
88
- :fatal ,
89
- :unknown ,
90
- ].each do |method|
91
- if not custom_tracer.respond_to?(method)
92
- raise ArgumentError, "trace logger must respond to #{method}"
93
- end
94
- end
95
-
96
- @trace_logger = custom_tracer
97
- end
98
-
99
- def log_msg(msg, level=Logger::INFO)
100
- return unless @logger
101
- @logger.add(level, msg)
102
- end
103
-
104
- def trace_msg(msg)
105
- return unless @trace_logger
106
- @trace_logger.info(msg)
107
- end
108
-
109
- # Provided for backwards compatibility.
110
- # Callers should be using the +level+ (on the +Logging+ module
111
- # or on the instance) to figure out what the log level is.
112
- def debug?
113
- self.level == Logger::DEBUG
114
- end
115
- def debug=(val)
116
- self.level = (val ? Logger::DEBUG : Logger::INFO)
117
- end
118
-
119
- end # module methods
120
-
121
- # Default logger to stdout.
122
- self.logger = Logger.new(STDOUT)
123
- self.logger.level = Logger::INFO
124
- self.logger.formatter = Logging::SimpleFormatter.new
125
-
126
- def silent
127
- Logging.silent?
128
- end
129
-
130
- def silent=(value)
131
- Logging.silent = value
132
- end
133
-
134
- # Log a message if tracing is activated
135
- def trace(msg=nil)
136
- Logging.trace_msg(msg) if msg
137
- end
138
- module_function :trace
139
- public :trace
140
-
141
- # Log a message at DEBUG level
142
- def log_debug(msg=nil)
143
- Logging.log_msg(msg || yield, Logger::DEBUG)
144
- end
145
- module_function :log_debug
146
- public :log_debug
147
-
148
- # Log a message at INFO level
149
- def log_info(msg)
150
- Logging.log_msg(msg || yield, Logger::INFO)
151
- end
152
- module_function :log_info
153
- public :log_info
154
-
155
- # Log a message at ERROR level (and maybe a backtrace)
156
- def log_error(msg, e=nil)
157
- log_msg = msg
158
- if e
159
- log_msg += ": #{e}\n\t" + e.backtrace.join("\n\t") + "\n"
160
- end
161
- Logging.log_msg(log_msg, Logger::ERROR)
162
- end
163
- module_function :log_error
164
- public :log_error
165
-
166
- # For backwards compatibility
167
- def log msg
168
- STDERR.puts('#log has been deprecated, please use the ' \
169
- 'log_level function instead (e.g. - log_info).')
170
- log_info(msg)
171
- end
172
-
173
- end
174
- end
@@ -1,216 +0,0 @@
1
- <%#
2
- # Taken from Rack::ShowException
3
- # adapted from Django <djangoproject.com>
4
- # Copyright (c) 2005, the Lawrence Journal-World
5
- # Used under the modified BSD license:
6
- # http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
7
- %>
8
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
9
- <html lang="en">
10
- <head>
11
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
12
- <meta name="robots" content="NONE,NOARCHIVE" />
13
- <title>Thin Stats</title>
14
- <style type="text/css">
15
- html * { padding:0; margin:0; }
16
- body * { padding:10px 20px; }
17
- body * * { padding:0; }
18
- body { font:small sans-serif; }
19
- body>div { border-bottom:1px solid #ddd; }
20
- h1 { font-weight:normal; }
21
- h2 { margin-bottom:.8em; }
22
- h2 span { font-size:80%; color:#666; font-weight:normal; }
23
- h3 { margin:1em 0 .5em 0; }
24
- h4 { margin:0 0 .5em 0; font-weight: normal; }
25
- table {
26
- border:1px solid #ccc; border-collapse: collapse; background:white; }
27
- tbody td, tbody th { vertical-align:top; padding:2px 3px; }
28
- thead th {
29
- padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
30
- font-weight:normal; font-size:11px; border:1px solid #ddd; }
31
- tbody th { text-align:right; color:#666; padding-right:.5em; }
32
- table.vars { margin:5px 0 2px 40px; }
33
- table.vars td, table.req td { font-family:monospace; }
34
- table td.code { width:100%;}
35
- table td.code div { overflow:hidden; }
36
- table.source th { color:#666; }
37
- table.source td {
38
- font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
39
- ul.traceback { list-style-type:none; }
40
- ul.traceback li.frame { margin-bottom:1em; }
41
- div.context { margin: 10px 0; }
42
- div.context ol {
43
- padding-left:30px; margin:0 10px; list-style-position: inside; }
44
- div.context ol li {
45
- font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
46
- div.context ol.context-line li { color:black; background-color:#ccc; }
47
- div.context ol.context-line li span { float: right; }
48
- div.commands { margin-left: 40px; }
49
- div.commands a { color:black; text-decoration:none; }
50
- #summary { background: #ffc; }
51
- #summary h2 { font-weight: normal; color: #666; }
52
- #summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
53
- #summary ul#quicklinks li { float: left; padding: 0 1em; }
54
- #summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
55
- #explanation { background:#eee; }
56
- #template, #template-not-exist { background:#f6f6f6; }
57
- #template-not-exist ul { margin: 0 0 0 20px; }
58
- #traceback { background:#eee; }
59
- #summary table { border:none; background:transparent; }
60
- #requests { background:#f6f6f6; padding-left:120px; }
61
- #requests h2, #requests h3 { position:relative; margin-left:-100px; }
62
- #requests h3 { margin-bottom:-1em; }
63
- .error { background: #ffc; }
64
- .specific { color:#cc3300; font-weight:bold; }
65
- </style>
66
- </head>
67
- <body>
68
-
69
- <div id="summary">
70
- <h1>Server stats</h1>
71
- <h2><%= Thin::SERVER %></h2>
72
- <table>
73
- <tr>
74
- <th>Uptime</th>
75
- <td><%= Time.now - @start_time %> sec</td>
76
- </tr>
77
- <tr>
78
- <th>PID</th>
79
- <td><%=h Process.pid %></td>
80
- </tr>
81
- </table>
82
-
83
- <% if @last_request %>
84
- <h3>Jump to:</h3>
85
- <ul id="quicklinks">
86
- <li><a href="#get-info">GET</a></li>
87
- <li><a href="#post-info">POST</a></li>
88
- <li><a href="#cookie-info">Cookies</a></li>
89
- <li><a href="#env-info">ENV</a></li>
90
- </ul>
91
- <% end %>
92
- </div>
93
-
94
- <div id="stats">
95
- <h2>Requests</h2>
96
- <h3>Stats</h3>
97
- <table class="req">
98
- <tr>
99
- <td>Requests</td>
100
- <td><%= @requests %></td>
101
- </tr>
102
- <tr>
103
- <td>Finished</td>
104
- <td><%= @requests_finished %></td>
105
- </tr>
106
- <tr>
107
- <td>Errors</td>
108
- <td><%= @requests - @requests_finished %></td>
109
- </tr>
110
- <tr>
111
- <td>Last request</td>
112
- <td><%= @last_request_time %> sec</td>
113
- </tr>
114
- </table>
115
- </div>
116
-
117
- <% if @last_request %>
118
- <div id="requestinfo">
119
- <h2>Last Request information</h2>
120
-
121
- <h3 id="get-info">GET</h3>
122
- <% unless @last_request.GET.empty? %>
123
- <table class="req">
124
- <thead>
125
- <tr>
126
- <th>Variable</th>
127
- <th>Value</th>
128
- </tr>
129
- </thead>
130
- <tbody>
131
- <% @last_request.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
132
- <tr>
133
- <td><%=h key %></td>
134
- <td class="code"><div><%=h val.inspect %></div></td>
135
- </tr>
136
- <% } %>
137
- </tbody>
138
- </table>
139
- <% else %>
140
- <p>No GET data.</p>
141
- <% end %>
142
-
143
- <h3 id="post-info">POST</h3>
144
- <% unless @last_request.POST.empty? %>
145
- <table class="req">
146
- <thead>
147
- <tr>
148
- <th>Variable</th>
149
- <th>Value</th>
150
- </tr>
151
- </thead>
152
- <tbody>
153
- <% @last_request.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
154
- <tr>
155
- <td><%=h key %></td>
156
- <td class="code"><div><%=h val.inspect %></div></td>
157
- </tr>
158
- <% } %>
159
- </tbody>
160
- </table>
161
- <% else %>
162
- <p>No POST data.</p>
163
- <% end %>
164
-
165
-
166
- <h3 id="cookie-info">COOKIES</h3>
167
- <% unless @last_request.cookies.empty? %>
168
- <table class="req">
169
- <thead>
170
- <tr>
171
- <th>Variable</th>
172
- <th>Value</th>
173
- </tr>
174
- </thead>
175
- <tbody>
176
- <% @last_request.cookies.each { |key, val| %>
177
- <tr>
178
- <td><%=h key %></td>
179
- <td class="code"><div><%=h val.inspect %></div></td>
180
- </tr>
181
- <% } %>
182
- </tbody>
183
- </table>
184
- <% else %>
185
- <p>No cookie data.</p>
186
- <% end %>
187
-
188
- <h3 id="env-info">Rack ENV</h3>
189
- <table class="req">
190
- <thead>
191
- <tr>
192
- <th>Variable</th>
193
- <th>Value</th>
194
- </tr>
195
- </thead>
196
- <tbody>
197
- <% @last_request.env.sort_by { |k, v| k.to_s }.each { |key, val| %>
198
- <tr>
199
- <td><%=h key %></td>
200
- <td class="code"><div><%=h val %></div></td>
201
- </tr>
202
- <% } %>
203
- </tbody>
204
- </table>
205
-
206
- </div>
207
- <% end %>
208
-
209
- <div id="explanation">
210
- <p>
211
- You're seeing this page because you use <code>Thin::Stats</code>.
212
- </p>
213
- </div>
214
-
215
- </body>
216
- </html>
data/lib/thin/stats.rb DELETED
@@ -1,52 +0,0 @@
1
- require 'erb'
2
-
3
- module Thin
4
- module Stats
5
- # Rack adapter to log stats about a Rack application.
6
- class Adapter
7
- include ERB::Util
8
-
9
- def initialize(app, path='/stats')
10
- @app = app
11
- @path = path
12
-
13
- @template = ERB.new(File.read(File.dirname(__FILE__) + '/stats.html.erb'))
14
-
15
- @requests = 0
16
- @requests_finished = 0
17
- @start_time = Time.now
18
- end
19
-
20
- def call(env)
21
- if env['PATH_INFO'].index(@path) == 0
22
- serve(env)
23
- else
24
- log(env) { @app.call(env) }
25
- end
26
- end
27
-
28
- def log(env)
29
- @requests += 1
30
- @last_request = Rack::Request.new(env)
31
- request_started_at = Time.now
32
-
33
- response = yield
34
-
35
- @requests_finished += 1
36
- @last_request_time = Time.now - request_started_at
37
-
38
- response
39
- end
40
-
41
- def serve(env)
42
- body = @template.result(binding)
43
-
44
- [
45
- 200,
46
- { 'Content-Type' => 'text/html' },
47
- [body]
48
- ]
49
- end
50
- end
51
- end
52
- end
data/lib/thin/statuses.rb DELETED
@@ -1,48 +0,0 @@
1
- module Thin
2
- # Every standard HTTP code mapped to the appropriate message.
3
- # Stolent from Mongrel.
4
- HTTP_STATUS_CODES = {
5
- 100 => 'Continue',
6
- 101 => 'Switching Protocols',
7
- 200 => 'OK',
8
- 201 => 'Created',
9
- 202 => 'Accepted',
10
- 203 => 'Non-Authoritative Information',
11
- 204 => 'No Content',
12
- 205 => 'Reset Content',
13
- 206 => 'Partial Content',
14
- 300 => 'Multiple Choices',
15
- 301 => 'Moved Permanently',
16
- 302 => 'Moved Temporarily',
17
- 303 => 'See Other',
18
- 304 => 'Not Modified',
19
- 305 => 'Use Proxy',
20
- 400 => 'Bad Request',
21
- 401 => 'Unauthorized',
22
- 402 => 'Payment Required',
23
- 403 => 'Forbidden',
24
- 404 => 'Not Found',
25
- 405 => 'Method Not Allowed',
26
- 406 => 'Not Acceptable',
27
- 407 => 'Proxy Authentication Required',
28
- 408 => 'Request Time-out',
29
- 409 => 'Conflict',
30
- 410 => 'Gone',
31
- 411 => 'Length Required',
32
- 412 => 'Precondition Failed',
33
- 413 => 'Request Entity Too Large',
34
- 414 => 'Request-URI Too Large',
35
- 415 => 'Unsupported Media Type',
36
- 422 => 'Unprocessable Entity',
37
- 428 => 'Precondition Required',
38
- 429 => 'Too Many Requests',
39
- 431 => 'Request Header Fields Too Large',
40
- 500 => 'Internal Server Error',
41
- 501 => 'Not Implemented',
42
- 502 => 'Bad Gateway',
43
- 503 => 'Service Unavailable',
44
- 504 => 'Gateway Time-out',
45
- 505 => 'HTTP Version not supported',
46
- 511 => 'Network Authentication Required'
47
- }
48
- end