thin 0.4.1 → 0.5.0

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 (91) hide show
  1. data/COPYING +18 -0
  2. data/README +32 -45
  3. data/Rakefile +66 -23
  4. data/bin/thin +76 -45
  5. data/doc/benchmarks.txt +64 -249
  6. data/doc/rdoc/created.rid +1 -1
  7. data/doc/rdoc/files/README.html +37 -100
  8. data/doc/rdoc/rdoc-style.css +5 -0
  9. data/example/config.ru +9 -0
  10. data/ext/thin_parser/common.rl +54 -0
  11. data/ext/thin_parser/ext_help.h +14 -0
  12. data/ext/thin_parser/extconf.rb +6 -0
  13. data/ext/thin_parser/parser.c +1199 -0
  14. data/ext/thin_parser/parser.h +49 -0
  15. data/ext/thin_parser/parser.rl +143 -0
  16. data/ext/thin_parser/thin.c +424 -0
  17. data/lib/rack/adapter/rails.rb +136 -0
  18. data/lib/rack/handler/thin.rb +13 -0
  19. data/lib/thin.rb +28 -12
  20. data/lib/thin/connection.rb +47 -0
  21. data/lib/thin/daemonizing.rb +5 -1
  22. data/lib/thin/headers.rb +3 -2
  23. data/lib/thin/logging.rb +6 -13
  24. data/lib/thin/request.rb +53 -133
  25. data/lib/thin/response.rb +21 -25
  26. data/lib/thin/server.rb +30 -94
  27. data/lib/thin/version.rb +2 -2
  28. data/lib/thin_parser.bundle +0 -0
  29. data/spec/daemonizing_spec.rb +94 -0
  30. data/spec/headers_spec.rb +35 -0
  31. data/spec/request_spec.rb +258 -0
  32. data/spec/response_spec.rb +40 -0
  33. data/spec/server_spec.rb +75 -0
  34. data/spec/spec_helper.rb +126 -0
  35. metadata +79 -99
  36. data/bin/thin_cluster +0 -53
  37. data/doc/rdoc/classes/Kernel.html +0 -182
  38. data/doc/rdoc/classes/Process.html +0 -175
  39. data/doc/rdoc/classes/Thin.html +0 -184
  40. data/doc/rdoc/classes/Thin/CGIWrapper.html +0 -438
  41. data/doc/rdoc/classes/Thin/Cluster.html +0 -392
  42. data/doc/rdoc/classes/Thin/Command.html +0 -221
  43. data/doc/rdoc/classes/Thin/CommandError.html +0 -154
  44. data/doc/rdoc/classes/Thin/Commands.html +0 -145
  45. data/doc/rdoc/classes/Thin/Daemonizable.html +0 -250
  46. data/doc/rdoc/classes/Thin/Daemonizable/ClassMethods.html +0 -203
  47. data/doc/rdoc/classes/Thin/DirHandler.html +0 -250
  48. data/doc/rdoc/classes/Thin/Handler.html +0 -195
  49. data/doc/rdoc/classes/Thin/Headers.html +0 -244
  50. data/doc/rdoc/classes/Thin/InvalidRequest.html +0 -150
  51. data/doc/rdoc/classes/Thin/Logging.html +0 -214
  52. data/doc/rdoc/classes/Thin/RailsHandler.html +0 -234
  53. data/doc/rdoc/classes/Thin/RailsServer.html +0 -175
  54. data/doc/rdoc/classes/Thin/Request.html +0 -379
  55. data/doc/rdoc/classes/Thin/Response.html +0 -311
  56. data/doc/rdoc/classes/Thin/Server.html +0 -381
  57. data/doc/rdoc/files/bin/thin.html +0 -188
  58. data/doc/rdoc/files/bin/thin_cluster.html +0 -175
  59. data/doc/rdoc/files/lib/thin/cgi_rb.html +0 -263
  60. data/doc/rdoc/files/lib/thin/cluster_rb.html +0 -263
  61. data/doc/rdoc/files/lib/thin/command_rb.html +0 -263
  62. data/doc/rdoc/files/lib/thin/consts_rb.html +0 -263
  63. data/doc/rdoc/files/lib/thin/daemonizing_rb.html +0 -263
  64. data/doc/rdoc/files/lib/thin/handler_rb.html +0 -263
  65. data/doc/rdoc/files/lib/thin/headers_rb.html +0 -263
  66. data/doc/rdoc/files/lib/thin/logging_rb.html +0 -263
  67. data/doc/rdoc/files/lib/thin/mime_types_rb.html +0 -263
  68. data/doc/rdoc/files/lib/thin/rails_rb.html +0 -263
  69. data/doc/rdoc/files/lib/thin/recipes_rb.html +0 -171
  70. data/doc/rdoc/files/lib/thin/request_rb.html +0 -171
  71. data/doc/rdoc/files/lib/thin/response_rb.html +0 -171
  72. data/doc/rdoc/files/lib/thin/server_rb.html +0 -171
  73. data/doc/rdoc/files/lib/thin/statuses_rb.html +0 -171
  74. data/doc/rdoc/files/lib/thin/version_rb.html +0 -171
  75. data/lib/thin/cgi.rb +0 -159
  76. data/lib/thin/cluster.rb +0 -147
  77. data/lib/thin/command.rb +0 -49
  78. data/lib/thin/commands/cluster/base.rb +0 -24
  79. data/lib/thin/commands/cluster/config.rb +0 -36
  80. data/lib/thin/commands/cluster/restart.rb +0 -35
  81. data/lib/thin/commands/cluster/start.rb +0 -40
  82. data/lib/thin/commands/cluster/stop.rb +0 -28
  83. data/lib/thin/commands/server/base.rb +0 -7
  84. data/lib/thin/commands/server/start.rb +0 -33
  85. data/lib/thin/commands/server/stop.rb +0 -29
  86. data/lib/thin/consts.rb +0 -37
  87. data/lib/thin/handler.rb +0 -57
  88. data/lib/thin/mime_types.rb +0 -619
  89. data/lib/thin/rails.rb +0 -44
  90. data/lib/thin/recipes.rb +0 -36
  91. data/lib/transat/parser.rb +0 -247
@@ -1,44 +0,0 @@
1
- module Thin
2
- # Forwards incoming request to Rails dispatcher.
3
- class RailsHandler < Handler
4
- def initialize(pwd, env='development')
5
- @env = env
6
- @pwd = pwd
7
- end
8
-
9
- def start
10
- ENV['RAILS_ENV'] = @env
11
-
12
- require "#{@pwd}/config/environment"
13
- require 'dispatcher'
14
- end
15
-
16
- def process(request, response)
17
- # Rails doesn't serve static files
18
- # TODO handle Rails page caching
19
- return false if File.file?(File.join(@pwd, 'public', request.path))
20
-
21
- cgi = CGIWrapper.new(request, response)
22
-
23
- Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
24
-
25
- # This finalizes the output using the proper HttpResponse way
26
- cgi.out("text/html", true) {""}
27
- end
28
-
29
- def to_s
30
- "Rails on #{@pwd} (env=#{@env})"
31
- end
32
- end
33
-
34
- # Serve the Rails application in the current directory.
35
- class RailsServer < Server
36
- def initialize(address, port, environment='development', cwd='.')
37
- super address, port,
38
- # Let Rails handle his thing and ignore files
39
- Thin::RailsHandler.new(cwd, environment),
40
- # Serve static files
41
- Thin::DirHandler.new(File.join(cwd, 'public'))
42
- end
43
- end
44
- end
@@ -1,36 +0,0 @@
1
- # == Set of Capistrano 2 recipes
2
- # To use, add on top of your Capfile file:
3
- # load 'config/deploy'
4
- # # ...
5
- # require 'thin'
6
- # require 'thin/recipes'
7
- #
8
- # === Configurable parameters
9
- # You can configure some parameters but it should work out of the box.
10
- # Path to the thin_cluster script, don't need to change this if
11
- # you installed thin as a gem on the server.
12
- # set :thin_cluster, "thin_cluster"
13
- # Location of the config file:
14
- # set :thin_config, "#{release_path}/config/thin.yml"
15
-
16
- Capistrano::Configuration.instance.load do
17
- set :thin_cluster, "thin_cluster"
18
- set :thin_config, "#{current_path}/config/thin.yml"
19
-
20
- namespace :deploy do
21
- desc 'Start Thin processes on the app server.'
22
- task :start, :roles => :app do
23
- run "#{thin_cluster} start -C #{thin_config}"
24
- end
25
-
26
- desc 'Stop the Thin processes on the app server.'
27
- task :stop, :roles => :app do
28
- run "#{thin_cluster} stop -C #{thin_config}"
29
- end
30
-
31
- desc 'Restart the Thin processes on the app server by starting and stopping the cluster.'
32
- task :restart, :roles => :app do
33
- run "#{thin_cluster} restart -C #{thin_config}"
34
- end
35
- end
36
- end
@@ -1,247 +0,0 @@
1
- # Original copy of this file taken from Piston
2
- # Copyright (c) 2006 Francois Beausoleil <francois@teksol.info>
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
-
22
- require "optparse"
23
-
24
- module Transat
25
- class VersionNeeded < StandardError; end
26
-
27
- class HelpNeeded < StandardError
28
- attr_reader :command
29
-
30
- def initialize(command)
31
- @command = command
32
- end
33
- end
34
-
35
- class NoCommandGiven < StandardError
36
- def message
37
- "No command given"
38
- end
39
- end
40
-
41
- class UnknownOptions < StandardError
42
- attr_reader :command
43
-
44
- def initialize(command, unrecognized_options)
45
- @command, @unrecognized_options = command, unrecognized_options
46
- end
47
-
48
- def message
49
- "Command #{@command} does not accept options #{@unrecognized_options.join(", ")}"
50
- end
51
- end
52
-
53
- class UnknownCommand < StandardError
54
- def initialize(command, parser)
55
- @command, @parser = command, parser
56
- end
57
-
58
- def message
59
- "Unknown command: #{@command.inspect}"
60
- end
61
- end
62
-
63
- class BaseCommand
64
- attr_reader :non_options, :options
65
- def initialize(non_options, options)
66
- @non_options, @options = non_options, options
67
- end
68
- end
69
-
70
- class VersionCommand < BaseCommand
71
- def run
72
- raise VersionNeeded
73
- end
74
- end
75
-
76
- class HelpCommand < BaseCommand
77
- def run
78
- raise HelpNeeded.new(non_options.first)
79
- end
80
- end
81
-
82
- class Parser
83
- def initialize(&block)
84
- @valid_options, @received_options, @commands = [], {}, {}
85
- @option_parser = OptionParser.new
86
-
87
- command(:help, Transat::HelpCommand)
88
- command(:version, Transat::VersionCommand)
89
- instance_eval(&block) if block_given?
90
- end
91
-
92
- def option(name, options={})
93
- options[:long] = name.to_s.gsub("_", "-") unless options[:long]
94
- @valid_options << name
95
- @received_options[name] = nil
96
-
97
- opt_args = []
98
- opt_args << "-#{options[:short]}" if options.has_key?(:short)
99
- opt_args << "--#{options[:long] || name}"
100
- opt_args << "=#{options[:param_name]}" if options.has_key?(:param_name)
101
- opt_args << options[:message]
102
- case options[:type]
103
- when :int, :integer
104
- opt_args << Integer
105
- when :float
106
- opt_args << Float
107
- when nil
108
- # NOP
109
- else
110
- raise ArgumentError, "Option #{name} has a bad :type parameter: #{options[:type].inspect}"
111
- end
112
-
113
- if options.has_key?(:default)
114
- opt_args << "(default: #{options[:default]})"
115
- @received_options[name] = options[:default]
116
- end
117
-
118
- @option_parser.on(*opt_args.compact) do |value|
119
- @received_options[name] = value
120
- end
121
-
122
- @option_parser.on_tail('-h', '--help') do
123
- raise HelpNeeded, nil
124
- end
125
-
126
- @option_parser.on_tail('-v', '--version') do
127
- raise VersionNeeded
128
- end
129
- end
130
-
131
- def command(name, klass, options={})
132
- @commands[name.to_s] = options.merge(:class => klass)
133
- end
134
-
135
- def help(message)
136
- @help = message
137
- end
138
-
139
- def parse_and_execute(args=ARGV)
140
- begin
141
- command, non_options = parse(args)
142
- execute(command, non_options)
143
- rescue HelpNeeded
144
- $stderr.puts usage($!.command)
145
- exit 1
146
- rescue VersionNeeded
147
- puts "#{program_name} #{version}"
148
- exit 0
149
- rescue NoCommandGiven, UnknownOptions, UnknownCommand
150
- $stderr.puts "Error: #{$!.message}"
151
- $stderr.puts usage($!.respond_to?(:command) ? $!.command : nil)
152
- exit 1
153
- end
154
- end
155
-
156
- def parse(args)
157
- non_options = @option_parser.parse(args)
158
- command = non_options.shift
159
- raise NoCommandGiven unless command
160
- return command, non_options
161
- end
162
-
163
- def execute(command, non_options)
164
- @commands.each do |command_name, options|
165
- command_klass = options[:class]
166
-
167
- aliases = [command_name]
168
- aliases += command_klass.aliases if command_klass.respond_to?(:aliases)
169
-
170
- valid_options = {}
171
- @received_options.each_pair do |name, value|
172
- valid_options[name] = value if options[:valid_options].include?(name)
173
- end if options[:valid_options]
174
-
175
- return command_klass.new(non_options, valid_options).run if aliases.include?(command)
176
- end
177
-
178
- raise UnknownCommand.new(command, self)
179
- end
180
-
181
- def usage(command=nil)
182
- message = []
183
-
184
- if command then
185
- command_klass = @commands[command][:class]
186
- help =
187
- if command_klass.respond_to?(:aliases) then
188
- "#{command} (#{command_klass.aliases.join(", ")})"
189
- else
190
- "#{command}"
191
- end
192
- help = "#{help}: #{command_klass.help}" if command_klass.respond_to?(:help)
193
- message << help
194
- message << command_klass.detailed_help if command_klass.respond_to?(:detailed_help)
195
- message << ""
196
- message << "Valid options:"
197
- command_options_summary(@commands[command], message)
198
- else
199
- message << "usage: #{program_name.downcase} <command> [options] [args...]"
200
- message << "Type '#{program_name.downcase} help <command>' for help on a specific command."
201
- message << "Type '#{program_name.downcase} version' to get this program's version."
202
- message << ""
203
- message << "Available commands are:"
204
- @commands.sort.each do |command, options|
205
- command_klass = options[:class]
206
- if command_klass.respond_to?(:aliases) then
207
- message << " #{command} (#{command_klass.aliases.join(", ")})"
208
- else
209
- message << " #{command}"
210
- end
211
- end
212
- if @help
213
- message << ""
214
- message << @help
215
- end
216
- end
217
-
218
- message.map {|line| line.chomp}.join("\n")
219
- end
220
-
221
- def command_options_summary(command, message=[])
222
- valid_options = (command[:valid_options] || []).collect { |opt| "--#{opt.to_s.tr('_', '-')}" }
223
- @option_parser.top.list.each do |opt|
224
- opt.summarize({}, {}, @option_parser.summary_width, @option_parser.summary_width - 1, @option_parser.summary_indent) do |line|
225
- message << line
226
- end if valid_options.include?(opt.long.to_s)
227
- end
228
- message
229
- end
230
-
231
- def program_name(value=nil)
232
- value ? @program_name = value : @program_name
233
- end
234
-
235
- def version(value=nil)
236
- if value then
237
- @version = value.respond_to?(:join) ? value.join(".") : value
238
- else
239
- @version
240
- end
241
- end
242
-
243
- def self.parse_and_execute(args=ARGV, &block)
244
- self.new(&block).parse_and_execute(args)
245
- end
246
- end
247
- end