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/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ *.log
3
+ *.pid
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
7
+ tmp
8
+ .yardoc
9
+ test.conf.rb
data/CHANGELOG CHANGED
@@ -1,90 +1,3 @@
1
- == 1.8.2 Ruby Razor
2
- * Ruby 3.2 support.
3
-
4
- == 1.8.1 Infinite Smoothie
5
- * Fix possible HTTP Response Splitting
6
-
7
- == 1.8.0 Possessed Pickle
8
- * Many things
9
-
10
- == 1.7.2 Bachmanity
11
- * Add config support for ssl_version and ssl_cipher_list [frameworked]
12
-
13
- == 1.7.1 Muffin Mode
14
- * Ruby 2.4 support (Fixnum deprecation) [nimish-mehta]
15
- * Allow ERB templates in config files [markets]
16
-
17
- == 1.7.0 Dunder Mifflin
18
- * Rack 2 support
19
- * Ensure Response body.close is called in the same thread
20
- Fixes issues with ActiveRecord connection management [#307]
21
- * Fix TCP/IP Backend reports incorrect port when asked to bind to 0 [meschbach]
22
- * Work with ruby 2.3's --enable-frozen-string-literal [jeremyevans]
23
-
24
- == 1.6.4 Gob Bluth
25
- * Increase REQUEST_PATH to 2048 symbols [X2rdas]
26
- * Fix warning in logger [tenderlove]
27
- * Add :timeout option for Rack::Server.new [sugitak]
28
- * When restarting, exit on a next tick so we can send response back to a client [rsamoilov]
29
- * Check for empty PID files [z1dane]
30
- * Update Event Machine version to 1.0.4, Ruby 2.2.0 fix [freemanoid]
31
-
32
- == 1.6.3 Protein Powder
33
- * Add HTTP 422 status code [rajcybage]
34
- * Add warning about EM reactor still running when stopping.
35
- * Remove version number from "Server" HTTP header. [benbasson]
36
- * Adding `--ssl-disable-verify` to allow disabling of client cert requests when SSL enabled [brucek]
37
- * Ensure Tempfiles created by a large request are closed and deleted. [Tonkpils]
38
-
39
- == 1.6.2 Doc Brown
40
- * No longer replace response's body on HEAD request. Ensuring body.close will be called.
41
- * Remove `---ssl-verify` option as EventMachine doesn't verify the certificate.
42
- * Fix env['rack.peer_cert'] to return SSL certifcate.
43
-
44
- == 1.6.1 Death Proof
45
- * Regression: Default logger to STDOUT when using outside of CLI.
46
- * Regression: Downgrade Rack required version back to 1.0 to work w/ prior Rails versions.
47
-
48
- == 1.6.0 Greek Yogurt
49
- * Accept absolute URL in request line, eg.: 'GET http://site.com/he/lo HTTP/1.1'.
50
- * HEAD request no longer return a body in the response.
51
- * No longer stop EventMachine's reactor loop unless it was started by Thin.
52
- * Make request env keys upcasing locale-agnostic.
53
- * Use Ruby's `Logger` for logging. [Akshay Moghe].
54
- The logger can now be set using `Thin::Logging.logger=`.
55
- Tracing of request is handled by a second logger, `Thin::Logging.trace_logger=`.
56
- * Add --threadpool-size option to configure EM's thread pool size (default: 20).
57
- * Pipelining is no longer supported.
58
-
59
- == 1.5.1 Straight Razor
60
- * Fix issue when running as another user/group without a PID file.
61
- * Allow overriding Connection & Server response headers.
62
- * Update vlad example [Mathieu Lemoine]
63
- * Keep connections in a Hash to speedup deletion [slivu]
64
- * Force kill using already known pid. Prevents "thin stop" from leaving a process that removed its
65
- pid file, but is still running (e.g. hung on some at_exit callback) [Michal Kwiatkowski]
66
-
67
- == 1.5.0 Knife
68
- * Fix compilation under Ubuntu 12.04 with -Werror=format-security option.
69
- * Raise an error when no PID file.
70
- * Prevent duplicate response headers.
71
- * Make proper response on exception [MasterLambaster].
72
- * Automatically close idling pipeline connections on server stop [MasterLambaster].
73
-
74
- == 1.4.1 Chromeo Fix
75
- * Fix error when sending USR1 signal and no log file is supplied.
76
-
77
- == 1.4.0 Chromeo
78
- * kill -USR1 $PID for log rotation [catwell].
79
- * Fix HUP signal being reseted after deamonization [atotic].
80
- * Fix error with nil addresses in Connection#socket_address.
81
-
82
- == 1.3.2 Low-bar Squat
83
- * Remove mack and halcyon Rack adapters from automatic detection.
84
-
85
- == 1.3.1 Triple Espresso
86
- * Fix service not working pre 1.9.
87
-
88
1
  == 1.3.0 Double Espresso
89
2
  * BREAKING CHANGE: Thin no longer ships with fat Windows binaries.
90
3
  From now on, to install on Windows, install https://github.com/oneclick/rubyinstaller/wiki/Development-Kit.
@@ -92,10 +5,10 @@
92
5
  It is now the responsibility of the app (or a middleware) to set the Content-Length.
93
6
  * Log errors to STDERR [textgoeshere]
94
7
  * Shut down gracefully when receiving SIGTERM [ddollar]
95
-
8
+
96
9
  Processes are allowed a chance to shut down gracefully when receiving
97
10
  SIGTERM (http://en.wikipedia.org/wiki/SIGTERM).
98
-
11
+
99
12
  On Heroku, when shutting down a process, we send a SIGTERM followed 10
100
13
  seconds later with a SIGKILL, similar to the behavior of the init daemon
101
14
  on most Unix systems. This patch will allow Heroku apps to shut down
@@ -120,7 +33,7 @@
120
33
  the existing connection to another protocol, and specifically is NOT
121
34
  used to upgrade a separate connection. Therefore, the connection must
122
35
  remain open after this response in order to facilitate that.
123
-
36
+
124
37
  * Accept IE7 badly encoded URL (eg.: %uEEEE)
125
38
  * Fix gemspec to work w/ Bundler [smparkes]
126
39
  * Add SSL support [tmm1]
@@ -136,10 +49,10 @@
136
49
  --ssl-key-file PATH Path to private key
137
50
  --ssl-cert-file PATH Path to certificate
138
51
  --ssl-verify Enables SSL certificate verification
139
-
52
+
140
53
  * Expose peer SSL certificate in env (rack.peer_cert) [fd]
141
54
  * Adjusting unix socket permissions to be more open [mbj]
142
-
55
+
143
56
  == 1.2.7 No Hup
144
57
  * Support multiple Ruby version (fat binaries under windows)
145
58
  * Do not trap unsupported HUP signal on Windows
@@ -163,7 +76,7 @@
163
76
  == 1.2.2 I Find Your Lack of Sauce Disturbing release
164
77
  * Fix force kill under 1.9 [Alexey Chebotar]
165
78
  * Fix regression when --only option is used w/ --socket.
166
- * Add process name 'tag' functionality. Easier to distinguish thin daemons
79
+ * Add process name 'tag' functionality. Easier to distinguish thin daemons
167
80
  from eachother in process listing [ctcherry]
168
81
 
169
82
  == 1.2.1 Asynctilicious Ultra Supreme release
@@ -173,11 +86,11 @@
173
86
  * Allow String for response body
174
87
  * Require openssl before eventmachine to prevent crash in 1.9
175
88
 
176
- == 1.2.0 Asynctilicious Supreme release
89
+ == 1.2.0 Asynctilicious Supreme release
177
90
  * Add support for Windows mingw Ruby distro [Juan C. Rodriguez]
178
91
  * Add async response support, see example/async_*.ru [raggi]
179
92
 
180
- == 1.1.1 Super Disco Power Plus release
93
+ == 1.1.1 Super Disco Power Plus release
181
94
  * Fix bug when running with only options [hasimo]
182
95
 
183
96
  == 1.1.0 Super Disco Power release
@@ -274,20 +187,20 @@
274
187
  * Add tasks for Vlad the Deployer in example/vlad.rake [cnantais]
275
188
  * Add Ramaze Rackup config file in example dir [tmm1]
276
189
  Use like this from you Ramaze app dir:
277
-
190
+
278
191
  thin start -r /path/to/thin/example/ramaze.ru
279
-
192
+
280
193
  * Add the --rackup option to load a Rack config file instead of the Rails adapter.
281
194
  So you can use any framework with the thin script and start cluster and stuff like that.
282
195
  A Rack config file is one that is usable through the rackup command and looks like this:
283
-
196
+
284
197
  use Rack::CommonLogger
285
198
  run MyCrazyRackAdapter.new(:uterly, 'cool')
286
-
199
+
287
200
  Then use it with thin like this:
288
-
201
+
289
202
  thin start --rackup config.ru
290
-
203
+
291
204
  * thin config --chrdir ... -C thin/yml do not change current directory anymore, fixes #33.
292
205
  * Add a better sample god config file in example/thin.god that loads all info from config
293
206
  files in /etc/thin. Drop-in replacement for the thin runlevel service [Gump].
@@ -295,9 +208,9 @@
295
208
  configuration.
296
209
  * Add a script to run thin as a runlevel service that can start at startup, closes #31 [Gump]
297
210
  Setup the service like this:
298
-
211
+
299
212
  sudo thin install /etc/thin
300
-
213
+
301
214
  This will install the boot script under /etc/init.d/thin. Then copy your config files to
302
215
  /etc/thin. Works only under Linux.
303
216
  * Set process name to 'thin server (0.0.0.0:3000)' when running as a daemon, closes #32.
@@ -323,9 +236,9 @@
323
236
  * Add example config files for http://www.tildeslash.com/monit usage.
324
237
  Include the example file using "include /path/to/thin/monit/file" in your monitrc file.
325
238
  The group settings let you do this to manage your clusters:
326
-
239
+
327
240
  sudo monit -g blog restart all
328
-
241
+
329
242
  There are examples of thin listening on sockets and thin listening on unix sockets.
330
243
 
331
244
  == 0.6.1 Cheesecake release
@@ -336,20 +249,20 @@
336
249
  * Add support for connection through UNIX domain socket.
337
250
  Use the --socket (-S) option w/ the thin script to configure the socket filename.
338
251
  Nginx support binding to a UNIX socket like this:
339
-
252
+
340
253
  upstream backend {
341
254
  server unix:/tmp/thin.0.sock;
342
255
  server unix:/tmp/thin.1.sock;
343
256
  server unix:/tmp/thin.2.sock;
344
257
  }
345
-
258
+
346
259
  Start your servers like this:
347
-
260
+
348
261
  thin start -s3 -S/tmp/thin.sock
349
-
262
+
350
263
  * Remove Server#listen! method. Use Server#start instead.
351
264
  * Server can now yield a Rack::Builder to allow building an app in one call:
352
-
265
+
353
266
  Server.start '0.0.0.0', 3000 do
354
267
  use Rack::CommonLogger
355
268
  use Rack::ShowExceptions
@@ -358,13 +271,13 @@
358
271
  run Rack::Lobster.new
359
272
  end
360
273
  end
361
-
274
+
362
275
  * Add a very basic stats page through Stats adapter, load w/ --stats and browse to /stats.
363
276
  * Add --trace (-V) option to trace request/response and get backtrace w/out all Ruby debug stuff.
364
277
  * Add --config (-C) option to load options from a config file in thin script [Matt Todd].
365
278
  * Alter response headers to output directly to a string.
366
279
  * Improve specs stability.
367
- * Move request body to a Tempfile if too big (> 112 KB)
280
+ * Move request body to a Tempfile if too big (> 112 MB)
368
281
  * Remove useless check for max header size in Request (already done in the parser)
369
282
 
370
283
  == 0.5.4 Flying Mustard release
@@ -376,7 +289,7 @@
376
289
  Thanks to Kent Sibilev and Ezra for their help on that one.
377
290
  * Add 'Server' response header
378
291
  * Fix --user and --group option not changing daemon process privileges
379
-
292
+
380
293
  == 0.5.3 Purple Yogurt release
381
294
  * win32 pre-compiled gem now available
382
295
  * change rake task configuration to allow win32 gem build
@@ -396,7 +309,7 @@
396
309
  --log-file => --log
397
310
  --pid-file => --pid
398
311
  --env => --environment
399
-
312
+
400
313
  == 0.5.1 LOLCAT release
401
314
  * Add URL rewriting to Rails adapter so that page caching works and / fetches index.html if present.
402
315
  * Fix bug in multiline response header parsing.
@@ -411,9 +324,9 @@
411
324
 
412
325
  == 0.5.0
413
326
  * Full rewrite to use EventMachine, Rack and Mongrel parser
414
-
327
+
415
328
  == 0.4.1
416
329
  * Fix Rails environment option not being used in thin script.
417
-
330
+
418
331
  == 0.4.0
419
332
  * First alphaish release as a gem.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in thin.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "mocha", "~> 0.10.0"
8
+ end
data/README.md CHANGED
@@ -1,102 +1,68 @@
1
- # Thin
2
-
3
- A small and fast Ruby web server
4
-
5
- ## Installation
6
-
7
- ```
8
- gem install thin
9
- ```
10
-
11
- Or add `thin` to your `Gemfile`:
12
-
13
- ```ruby
14
- gem 'thin'
15
- ```
16
-
17
- ## Usage
1
+ ---
18
2
 
19
- A +thin+ script offers an easy way to start your Rack application:
3
+ # This is alpha software. Things might break, people will cry and it will be your fault.
4
+ ### When reporting issues, make sure to mention you're using Thin v2.
20
5
 
21
- ```
22
- thin start
23
- ```
6
+ ---
24
7
 
25
- Browse the `example` directory for sample applications.
26
-
27
- ## Usage with Rails Action Cable
8
+ # Thin
9
+ Tiny, fast & funny Ruby server
28
10
 
29
- To use Thin with Action Cable, add the following to your `Gemfile`:
11
+ Thin is a high performance and customizable Ruby server. It's structured much like Nginx. A
12
+ master process listen to incoming requests and dispatch to its worker processes, each one
13
+ running an EventMachine event loop.
30
14
 
31
- ```ruby
32
- gem 'faye-websocket'
33
- gem 'thin' # If not already done
34
- ```
15
+ Which makes it, with all humility, the most secure, stable, fast and extensible Ruby web server
16
+ bundled in an easy to use gem for your own pleasure.
35
17
 
36
- Create a `config/initializers/thin_action_cable.rb`:
18
+ **Site:** http://code.macournoyer.com/thin/
19
+ **Group:** http://groups.google.com/group/thin-ruby/topics
20
+ **Bugs:** http://github.com/macournoyer/thin/issues
21
+ **Code:** http://github.com/macournoyer/thin
22
+ **IRC:** #thin on freenode
37
23
 
38
- ```ruby
39
- Rails.application.config.action_cable.use_faye = true
40
- Faye::WebSocket.load_adapter 'thin'
41
- ```
24
+ ## Features
42
25
 
43
- ### CLI
26
+ * Prefork model with an EventMachine loop running in each worker.
27
+ * Optional single process mode for non-UNIX systems and simpler deployments.
28
+ * Optional threaded mode using a pool of threads.
29
+ * Easy asynchronous streaming response support with chunked encoding.
30
+ * Fast file serving with automatic streaming for large files.
31
+ * Keep-alive support.
32
+ * SSL support (upcoming).
44
33
 
45
- Use a rackup (config.ru) file and bind to localhost port 8080:
34
+ ## Installation
35
+ For this pre-release of version 2.0:
46
36
 
47
- ```
48
- thin -R config.ru -a 127.0.0.1 -p 8080 start
49
- ```
37
+ $ gem install thin --pre
50
38
 
51
- Store the server process ID, log to a file and daemonize:
39
+ Or from source:
52
40
 
53
- ```
54
- thin -p 9292 -P tmp/pids/thin.pid -l logs/thin.log -d start
55
- ```
41
+ $ git clone git://github.com/macournoyer/thin.git
42
+ $ git checkout v2
43
+ $ cd thin
44
+ $ bundle install
45
+ $ rake install
56
46
 
57
- Thin is quite flexible in that many options can be specified at the command line (see `thin -h` for more).
47
+ ## Usage
48
+ The `thin` script offers an easy way to start your Rack based application and acts just like
49
+ the `rackup` script.:
58
50
 
59
- ### Configuration files
51
+ $ cd to/your/rack/app
52
+ $ thin
60
53
 
61
- You can create a configuration file using `thin config -C config/thin.yml`.
54
+ To use with Rails, add thin to your Gemfile and use Rails server command:
62
55
 
63
- You can then use it with all commands, such as: `thin start -C config/thin.yml`.
56
+ $ echo "gem 'thin'" >> Gemfile
57
+ $ bundle install
58
+ $ rails server thin
64
59
 
65
- Here is an example config file:
60
+ See examples/thin.conf.rb for a sample configuration file.
66
61
 
67
- ```yaml
68
- ---
69
- user: www-data
70
- group: www-data
71
- pid: tmp/pids/thin.pid
72
- timeout: 30
73
- wait: 30
74
- log: log/thin.log
75
- max_conns: 1024
76
- require: []
77
- environment: production
78
- max_persistent_conns: 512
79
- servers: 1
80
- threaded: true
81
- no-epoll: true
82
- daemonize: true
83
- socket: tmp/sockets/thin.sock
84
- chdir: /path/to/your/apps/root
85
- tag: a-name-to-show-up-in-ps aux
86
- ```
62
+ Run `thin -h` to list available options.
87
63
 
88
64
  ## License
89
-
90
65
  Ruby License, http://www.ruby-lang.org/en/LICENSE.txt.
91
66
 
92
67
  ## Credits
93
-
94
- The parser was originally from Mongrel http://mongrel.rubyforge.org by Zed Shaw.
95
- Mongrel is copyright 2007 Zed A. Shaw and contributors. It is licensed under
96
- the Ruby license and the GPL2.
97
-
98
68
  Thin is copyright Marc-Andre Cournoyer <macournoyer@gmail.com>
99
-
100
- Get help at http://groups.google.com/group/thin-ruby/
101
- Report bugs at https://github.com/macournoyer/thin/issues
102
- and major security issues directly to me at macournoyer@gmail.com.
data/Rakefile CHANGED
@@ -1,25 +1,35 @@
1
- require 'rake'
2
- require 'rake/clean'
3
- load 'thin.gemspec'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
4
3
 
5
- # Load tasks in tasks/
6
- Dir['tasks/**/*.rake'].each { |rake| load rake }
4
+ require 'rake/testtask'
5
+ require "thin/version"
7
6
 
8
- task :default => :spec
9
-
10
- desc "Build gem packages"
11
- task :build do
12
- sh "gem build thin.gemspec"
7
+ namespace :test do
8
+ Rake::TestTask.new(:unit) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/unit/**/*_test.rb'
12
+ end
13
+
14
+ Rake::TestTask.new(:integration) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/integration/**/*_test.rb'
18
+ end
19
+
13
20
  end
21
+ desc "Run all tests"
22
+ task :test => ["test:unit", "test:integration"]
14
23
 
15
- desc "Push gem packages"
16
- task :push => :build do
17
- sh "gem push thin-*.gem"
18
- end
24
+ task :default => :test
19
25
 
20
- task :install => :build do
21
- sh "gem install thin-*.gem"
26
+ task :man do
27
+ ENV['RONN_MANUAL'] = "Thin Manual"
28
+ ENV['RONN_ORGANIZATION'] = "Thin #{Thin::VERSION::STRING}"
29
+ sh "ronn -w -s toc -5 man/*.ronn"
30
+ mv FileList["man/*.html"], "site/public/man"
22
31
  end
23
32
 
24
- desc "Release version #{Thin::VERSION::STRING}"
25
- task :release => [:tag, :push]
33
+ task :rm_space do
34
+ sh %{find . -name "*.rb" -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"}
35
+ end
data/bin/thin CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # Thin command line interface script.
3
- # Run <tt>thin -h</tt> to get more usage.
4
2
 
5
- require 'thin'
6
- Thin::Runner.new(ARGV).run!
3
+ require "thin"
4
+ require "thin/runner"
5
+
6
+ Thin::Runner.run(ARGV)
data/examples/async.ru ADDED
@@ -0,0 +1,21 @@
1
+ require "thin/async"
2
+
3
+ class Async
4
+ def call(env)
5
+ response = Thin::AsyncResponse.new(env)
6
+
7
+ # Webkit requires some padding before displaying something.
8
+ response << " " * 1024
9
+
10
+ response << "this is ... "
11
+ # Will be sent to the browse 1 sec after.
12
+ EM.add_timer(1) do
13
+ response << "async stuff!"
14
+ response.done # close the connection
15
+ end
16
+
17
+ response.finish
18
+ end
19
+ end
20
+
21
+ run Async.new
@@ -0,0 +1,39 @@
1
+ # Event backend options
2
+ worker_connections 1024
3
+ # Disabling epoll or kqueue will fallback to select.
4
+ # use_epoll false
5
+ # use_kqueue false
6
+
7
+ # Threading
8
+ # For slow apps, you can enable the use of threads.
9
+ # If you're using this in Rails, make sure to call config.threadsafe!
10
+ threaded true # Call the app in a thread.
11
+ thread_pool_size 20
12
+
13
+ # Worker options
14
+ # worker_processes 0 # runs in a single process w/ limited features.
15
+ worker_processes 4
16
+ timeout 30 # seconds
17
+
18
+ # Preload the app (the .ru file) before forking to workers.
19
+ # Enable with copy-on-write garbage collection for better memory usage.
20
+ preload_app true
21
+
22
+ # Logging
23
+ log_path "./thin.log"
24
+ pid_path "./thin.pid"
25
+
26
+ # Listeners
27
+ listen 3000, :backlog => 1024, :tcp_no_delay => true
28
+ listen "0.0.0.0:8080"
29
+ listen "[::]:8081" # IPv6
30
+ listen "/tmp/thin.sock" # UNIX domain socket
31
+
32
+ # Callbacks
33
+ before_fork do |server|
34
+ puts "Preparing to fork a new worker ..."
35
+ end
36
+
37
+ after_fork do |server|
38
+ puts "Worker forked!"
39
+ end
data/lib/thin/async.rb ADDED
@@ -0,0 +1,108 @@
1
+ module Thin
2
+ unless defined?(DeferrableBody)
3
+ # Based on version from James Tucker <raggi@rubyforge.org>
4
+ class DeferrableBody
5
+ include EM::Deferrable
6
+
7
+ def initialize
8
+ @queue = []
9
+ end
10
+
11
+ def call(body)
12
+ @queue << body
13
+ schedule_dequeue
14
+ end
15
+
16
+ def each(&blk)
17
+ @body_callback = blk
18
+ schedule_dequeue
19
+ end
20
+
21
+ private
22
+ def schedule_dequeue
23
+ return unless @body_callback
24
+ EM.next_tick do
25
+ next unless body = @queue.shift
26
+ body.each do |chunk|
27
+ @body_callback.call(chunk)
28
+ end
29
+ schedule_dequeue unless @queue.empty?
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ # Response whos body is sent asynchronously.
36
+ #
37
+ # A nice wrapper around Thin's obscure async callback used to send response body asynchronously.
38
+ # Which means you can send the response in chunks while allowing Thin to process other requests.
39
+ #
40
+ # Crazy delicious with em-http-request for file upload, image processing, proxying, etc.
41
+ #
42
+ # == _WARNING_
43
+ # You should not use long blocking operations (Net::HTTP or slow shell calls) with this as it
44
+ # will prevent the EventMachine event loop from running and block all other requests.
45
+ #
46
+ # Also disable the Rack::Lint middleware to use Thin's async feature since it requires sending
47
+ # back an invalid status code to the server.
48
+ #
49
+ # == Usage
50
+ # Inside your Rack app #call(env):
51
+ #
52
+ # response = Thin::AsyncResponse.new(env)
53
+ # response.status = 201
54
+ # response.headers["X-Muffin-Mode"] = "ACTIVATED!"
55
+ #
56
+ # response << "this is ... "
57
+ #
58
+ # EM.add_timer(1) do
59
+ # # This will be sent to the client 1 sec later without blocking other requests.
60
+ # response << "async!"
61
+ # response.done
62
+ # end
63
+ #
64
+ # response.finish
65
+ #
66
+ class AsyncResponse
67
+ include Rack::Response::Helpers
68
+
69
+ Marker = [-1, {}, []].freeze
70
+
71
+ attr_reader :headers, :callback
72
+ attr_accessor :status
73
+
74
+ def initialize(env, status=200, headers={})
75
+ @callback = env['async.callback']
76
+ @body = DeferrableBody.new
77
+ @status = status
78
+ @headers = headers
79
+ @headers_sent = false
80
+
81
+ yield self if block_given?
82
+ end
83
+
84
+ def send_headers(response=nil)
85
+ return if @headers_sent
86
+ @callback.call response || [@status, @headers, @body]
87
+ @headers_sent = true
88
+ end
89
+
90
+ def write(body)
91
+ send_headers
92
+ @body.call(body.respond_to?(:each) ? body : [body])
93
+ end
94
+ alias :<< :write
95
+
96
+ # Tell Thin the response is complete and the connection can be closed.
97
+ def done(response=nil)
98
+ send_headers(response)
99
+ EM.next_tick { @body.succeed }
100
+ end
101
+
102
+ # Tell Thin the response is gonna be sent asynchronously.
103
+ # The status code of -1 is the magic trick here.
104
+ def finish
105
+ Marker
106
+ end
107
+ end
108
+ end