mongrel 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/README +4 -1
  2. data/Rakefile +1 -1
  3. data/bin/mongrel_rails +77 -24
  4. data/doc/rdoc/classes/Mongrel.html +0 -30
  5. data/doc/rdoc/classes/Mongrel/DirHandler.html +45 -26
  6. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000022.html +20 -0
  7. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000023.html +29 -7
  8. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000024.html +27 -29
  9. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000025.html +18 -27
  10. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000026.html +25 -18
  11. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000027.html +5 -25
  12. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000047.html +4 -4
  13. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000048.html +4 -4
  14. data/doc/rdoc/classes/Mongrel/HttpParser.html +35 -35
  15. data/doc/rdoc/classes/Mongrel/HttpParser.src/{M000022.html → M000015.html} +6 -6
  16. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000016.html +6 -5
  17. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000017.html +7 -7
  18. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000018.html +20 -8
  19. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000019.html +6 -20
  20. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000020.html +5 -5
  21. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000021.html +6 -5
  22. data/doc/rdoc/classes/Mongrel/HttpServer.html +1 -1
  23. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000028.html +16 -9
  24. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000029.html +49 -49
  25. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000030.html +9 -9
  26. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000031.html +4 -4
  27. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000032.html +4 -4
  28. data/doc/rdoc/created.rid +1 -1
  29. data/doc/rdoc/files/README.html +7 -2
  30. data/doc/rdoc/files/lib/mongrel_rb.html +1 -1
  31. data/doc/rdoc/fr_method_index.html +15 -15
  32. data/lib/mongrel.rb +17 -8
  33. metadata +4 -5
  34. data/doc/rdoc/classes/Mongrel.src/M000015.html +0 -18
data/README CHANGED
@@ -11,7 +11,7 @@ scream without too many portability issues.
11
11
 
12
12
  == Status
13
13
 
14
- The 0.3.1 release support Ruby On Rails much better than previously, and also
14
+ The 0.3.2 release supports Ruby On Rails much better than previously, and also
15
15
  sports the beginning of a command and plugin infrastructure. This last part
16
16
  isn't documented yet.
17
17
 
@@ -37,6 +37,9 @@ And you can stop it whenever you like with:
37
37
  All of which should be done from your application's directory. It writes the
38
38
  PID of the process you ran into log/mongrel.pid.
39
39
 
40
+ There are also many more new options for configuring the rails runner including
41
+ changing to a different directory, adding more MIME types, and setting processor
42
+ threads and timeouts.
40
43
 
41
44
  == Install
42
45
 
data/Rakefile CHANGED
@@ -31,6 +31,6 @@ setup_extension("http11", "http11")
31
31
 
32
32
  summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps."
33
33
  test_file = "test/test_ws.rb"
34
- setup_gem("mongrel", "0.3.1", "Zed A. Shaw", summary, ['mongrel_rails'], test_file) do |spec|
34
+ setup_gem("mongrel", "0.3.2", "Zed A. Shaw", summary, ['mongrel_rails'], test_file) do |spec|
35
35
  spec.add_dependency('daemons', '>= 0.4.2')
36
36
  end
@@ -51,9 +51,13 @@ end
51
51
 
52
52
 
53
53
  class RailsHandler < Mongrel::HttpHandler
54
- def initialize(dir)
54
+
55
+ def initialize(dir, mime_map = {})
55
56
  @files = Mongrel::DirHandler.new(dir,false)
56
57
  @guard = Mutex.new
58
+
59
+ # register the requested mime types
60
+ mime_map.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) }
57
61
  end
58
62
 
59
63
  def process(request, response)
@@ -88,50 +92,94 @@ class StartCommand < Mongrel::Command::Command
88
92
 
89
93
  def configure
90
94
  options [
91
- ["-e", "--environment ENV", "Rails environment to run as", :@environment, "production"],
92
- ["-d", "--daemonize", "Whether to run in the background or not", :@daemon, false],
93
- ['-p', '--port PORT', "Which port to bind to", :@port, 3000],
94
- ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
95
- ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
96
- ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"]
95
+ ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
96
+ ["-d", "--daemonize", "Whether to run in the background or not", :@daemon, false],
97
+ ['-p', '--port PORT', "Which port to bind to", :@port, 3000],
98
+ ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
99
+ ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
100
+ ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
101
+ ['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, 20],
102
+ ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, 120],
103
+ ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
104
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
105
+ ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
97
106
  ]
98
107
  end
99
108
 
100
109
  def validate
101
- valid? ["production","development"].include?(@environment), "Only valid environments are 'production' or 'development'"
110
+ @cwd = File.expand_path(@cwd)
111
+ valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
112
+
113
+ # change there to start, then we'll have to come back after daemonize
114
+ Dir.chdir(@cwd)
115
+
102
116
  valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file"
103
117
  valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file"
104
-
118
+ valid_dir? @docroot, "Path to docroot not valid: #@docroot"
119
+ valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
120
+
105
121
  return @valid
106
122
  end
107
123
 
108
-
109
- def run
110
- cwd = Dir.pwd
111
-
124
+ def daemonize
125
+ # save this for later since daemonize will hose it
112
126
  if @daemon
113
- puts "Running as Daemon at #@address:#@port"
127
+ puts "Started Mongrel server in #@environment mode at #@address:#@port"
114
128
  Daemonize.daemonize(log_file=@log_file)
115
- open(File.join(cwd,@pid_file),"w") {|f| f.write(Process.pid) }
129
+
116
130
  # change back to the original starting directory
117
- Dir.chdir(cwd)
131
+ Dir.chdir(@cwd)
132
+
133
+ open(@pid_file,"w") {|f| f.write(Process.pid) }
118
134
  else
119
- puts "Running at #@address:#@port"
135
+ puts "Running Mongrel server in #@environment mode at #@address:#@port"
120
136
  end
137
+ end
121
138
 
122
- ENV['RAILS_ENV'] = @environment
139
+ def load_mime_map
140
+ mime = {}
141
+
142
+ # configure any requested mime map
143
+ if @mime_map
144
+ puts "Loading additional MIME types from #@mime_map"
145
+ mime.merge!(YAML.load_file(@mime_map))
123
146
 
147
+ # check all the mime types to make sure they are the right format
148
+ mime.each {|k,v| puts "WARNING: MIME type #{k} must start with '.'" if k.index(".") != 0 }
149
+ end
150
+
151
+ return mime
152
+ end
153
+
154
+ def configure_rails
155
+ ENV['RAILS_ENV'] = @environment
124
156
  require 'config/environment'
125
- h = Mongrel::HttpServer.new(@address, @port)
126
- h.register("/", RailsHandler.new(File.join(cwd,"public")))
127
- h.run
157
+
158
+ # configure the rails handler
159
+ rails = RailsHandler.new(@docroot, load_mime_map)
160
+
161
+ return rails
162
+ end
163
+
164
+ def start_mongrel(rails)
165
+ # start up mongrel with the right configurations
166
+ server = Mongrel::HttpServer.new(@address, @port, @num_procs.to_i, @timeout.to_i)
167
+ server.register("/", rails)
168
+ server.run
128
169
 
129
170
  begin
130
- h.acceptor.join
171
+ puts "Server ready."
172
+ server.acceptor.join
131
173
  rescue Interrupt
132
174
  puts "Interrupted."
133
175
  end
134
176
  end
177
+
178
+ def run
179
+ daemonize
180
+ rails = configure_rails
181
+ start_mongrel(rails)
182
+ end
135
183
  end
136
184
 
137
185
 
@@ -140,13 +188,18 @@ class StopCommand < Mongrel::Command::Command
140
188
 
141
189
  def configure
142
190
  options [
143
- ["-d", "--daemonize", "Whether to run in the background or not", :@daemon, false],
144
- ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"]
191
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
192
+ ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"]
145
193
  ]
146
194
  end
147
195
 
148
196
  def validate
197
+ @cwd = File.expand_path(@cwd)
198
+ valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
199
+
200
+ @pid_file = File.join(@cwd,@pid_file)
149
201
  valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
202
+
150
203
  return @valid
151
204
  end
152
205
 
@@ -89,13 +89,6 @@ to service web application requests fast as possible.
89
89
 
90
90
  </div>
91
91
 
92
- <div id="method-list">
93
- <h3 class="section-bar">Methods</h3>
94
-
95
- <div class="name-list">
96
- <a href="#M000015">add_mime_type</a>&nbsp;&nbsp;
97
- </div>
98
- </div>
99
92
 
100
93
  </div>
101
94
 
@@ -148,29 +141,6 @@ href="Mongrel/Const.html">Mongrel::Const</a>.
148
141
 
149
142
 
150
143
  <!-- if method_list -->
151
- <div id="methods">
152
- <h3 class="section-bar">Public Instance methods</h3>
153
-
154
- <div id="method-M000015" class="method-detail">
155
- <a name="M000015"></a>
156
-
157
- <div class="method-heading">
158
- <a href="Mongrel.src/M000015.html" target="Code" class="method-signature"
159
- onclick="popupCode('Mongrel.src/M000015.html');return false;">
160
- <span class="method-name">add_mime_type</span><span class="method-args">(extension, type)</span>
161
- </a>
162
- </div>
163
-
164
- <div class="method-description">
165
- <p>
166
- There is a small number of default mime types for extensions, but this lets
167
- you add any others you&#8217;ll need when serving content.
168
- </p>
169
- </div>
170
- </div>
171
-
172
-
173
- </div>
174
144
 
175
145
 
176
146
  </div>
@@ -103,11 +103,12 @@ than it simply gives a 404.
103
103
  <h3 class="section-bar">Methods</h3>
104
104
 
105
105
  <div class="name-list">
106
- <a href="#M000024">can_serve</a>&nbsp;&nbsp;
107
- <a href="#M000023">new</a>&nbsp;&nbsp;
108
- <a href="#M000027">process</a>&nbsp;&nbsp;
109
- <a href="#M000025">send_dir_listing</a>&nbsp;&nbsp;
110
- <a href="#M000026">send_file</a>&nbsp;&nbsp;
106
+ <a href="#M000027">add_mime_type</a>&nbsp;&nbsp;
107
+ <a href="#M000023">can_serve</a>&nbsp;&nbsp;
108
+ <a href="#M000022">new</a>&nbsp;&nbsp;
109
+ <a href="#M000026">process</a>&nbsp;&nbsp;
110
+ <a href="#M000024">send_dir_listing</a>&nbsp;&nbsp;
111
+ <a href="#M000025">send_file</a>&nbsp;&nbsp;
111
112
  </div>
112
113
  </div>
113
114
 
@@ -155,12 +156,30 @@ than it simply gives a 404.
155
156
  <div id="methods">
156
157
  <h3 class="section-bar">Public Class methods</h3>
157
158
 
158
- <div id="method-M000023" class="method-detail">
159
- <a name="M000023"></a>
159
+ <div id="method-M000027" class="method-detail">
160
+ <a name="M000027"></a>
160
161
 
161
162
  <div class="method-heading">
162
- <a href="DirHandler.src/M000023.html" target="Code" class="method-signature"
163
- onclick="popupCode('DirHandler.src/M000023.html');return false;">
163
+ <a href="DirHandler.src/M000027.html" target="Code" class="method-signature"
164
+ onclick="popupCode('DirHandler.src/M000027.html');return false;">
165
+ <span class="method-name">add_mime_type</span><span class="method-args">(extension, type)</span>
166
+ </a>
167
+ </div>
168
+
169
+ <div class="method-description">
170
+ <p>
171
+ There is a small number of default mime types for extensions, but this lets
172
+ you add any others you&#8217;ll need when serving content.
173
+ </p>
174
+ </div>
175
+ </div>
176
+
177
+ <div id="method-M000022" class="method-detail">
178
+ <a name="M000022"></a>
179
+
180
+ <div class="method-heading">
181
+ <a href="DirHandler.src/M000022.html" target="Code" class="method-signature"
182
+ onclick="popupCode('DirHandler.src/M000022.html');return false;">
164
183
  <span class="method-name">new</span><span class="method-args">(path, listing_allowed=true, index_html=&quot;index.html&quot;)</span>
165
184
  </a>
166
185
  </div>
@@ -174,12 +193,12 @@ You give it the path to the directory root and an (optional)
174
193
 
175
194
  <h3 class="section-bar">Public Instance methods</h3>
176
195
 
177
- <div id="method-M000024" class="method-detail">
178
- <a name="M000024"></a>
196
+ <div id="method-M000023" class="method-detail">
197
+ <a name="M000023"></a>
179
198
 
180
199
  <div class="method-heading">
181
- <a href="DirHandler.src/M000024.html" target="Code" class="method-signature"
182
- onclick="popupCode('DirHandler.src/M000024.html');return false;">
200
+ <a href="DirHandler.src/M000023.html" target="Code" class="method-signature"
201
+ onclick="popupCode('DirHandler.src/M000023.html');return false;">
183
202
  <span class="method-name">can_serve</span><span class="method-args">(path_info)</span>
184
203
  </a>
185
204
  </div>
@@ -192,12 +211,12 @@ not).
192
211
  </div>
193
212
  </div>
194
213
 
195
- <div id="method-M000027" class="method-detail">
196
- <a name="M000027"></a>
214
+ <div id="method-M000026" class="method-detail">
215
+ <a name="M000026"></a>
197
216
 
198
217
  <div class="method-heading">
199
- <a href="DirHandler.src/M000027.html" target="Code" class="method-signature"
200
- onclick="popupCode('DirHandler.src/M000027.html');return false;">
218
+ <a href="DirHandler.src/M000026.html" target="Code" class="method-signature"
219
+ onclick="popupCode('DirHandler.src/M000026.html');return false;">
201
220
  <span class="method-name">process</span><span class="method-args">(request, response)</span>
202
221
  </a>
203
222
  </div>
@@ -210,12 +229,12 @@ allowed (based on the listing_allowed paramter to the constructor).
210
229
  </div>
211
230
  </div>
212
231
 
213
- <div id="method-M000025" class="method-detail">
214
- <a name="M000025"></a>
232
+ <div id="method-M000024" class="method-detail">
233
+ <a name="M000024"></a>
215
234
 
216
235
  <div class="method-heading">
217
- <a href="DirHandler.src/M000025.html" target="Code" class="method-signature"
218
- onclick="popupCode('DirHandler.src/M000025.html');return false;">
236
+ <a href="DirHandler.src/M000024.html" target="Code" class="method-signature"
237
+ onclick="popupCode('DirHandler.src/M000024.html');return false;">
219
238
  <span class="method-name">send_dir_listing</span><span class="method-args">(base, dir, response)</span>
220
239
  </a>
221
240
  </div>
@@ -225,18 +244,18 @@ allowed (based on the listing_allowed paramter to the constructor).
225
244
  Returns a simplistic directory listing if they&#8217;re enabled, otherwise
226
245
  a 403. Base is the base URI from the REQUEST_URI, dir is the directory to
227
246
  serve on the file system (comes from <a
228
- href="DirHandler.html#M000024">can_serve</a>()), and response is the <a
247
+ href="DirHandler.html#M000023">can_serve</a>()), and response is the <a
229
248
  href="HttpResponse.html">HttpResponse</a> object to send the results on.
230
249
  </p>
231
250
  </div>
232
251
  </div>
233
252
 
234
- <div id="method-M000026" class="method-detail">
235
- <a name="M000026"></a>
253
+ <div id="method-M000025" class="method-detail">
254
+ <a name="M000025"></a>
236
255
 
237
256
  <div class="method-heading">
238
- <a href="DirHandler.src/M000026.html" target="Code" class="method-signature"
239
- onclick="popupCode('DirHandler.src/M000026.html');return false;">
257
+ <a href="DirHandler.src/M000025.html" target="Code" class="method-signature"
258
+ onclick="popupCode('DirHandler.src/M000025.html');return false;">
240
259
  <span class="method-name">send_file</span><span class="method-args">(req, response)</span>
241
260
  </a>
242
261
  </div>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new (Mongrel::DirHandler)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 470</span>
14
+ 470: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">listing_allowed</span>=<span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">index_html</span>=<span class="ruby-value str">&quot;index.html&quot;</span>)
15
+ 471: <span class="ruby-ivar">@path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>)
16
+ 472: <span class="ruby-ivar">@listing_allowed</span>=<span class="ruby-identifier">listing_allowed</span>
17
+ 473: <span class="ruby-ivar">@index_html</span> = <span class="ruby-identifier">index_html</span>
18
+ 474: <span class="ruby-keyword kw">end</span></pre>
19
+ </body>
20
+ </html>
@@ -5,16 +5,38 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>new (Mongrel::DirHandler)</title>
8
+ <title>can_serve (Mongrel::DirHandler)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 463</span>
14
- 463: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">listing_allowed</span>=<span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">index_html</span>=<span class="ruby-value str">&quot;index.html&quot;</span>)
15
- 464: <span class="ruby-ivar">@path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>)
16
- 465: <span class="ruby-ivar">@listing_allowed</span>=<span class="ruby-identifier">listing_allowed</span>
17
- 466: <span class="ruby-ivar">@index_html</span> = <span class="ruby-identifier">index_html</span>
18
- 467: <span class="ruby-keyword kw">end</span></pre>
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 477</span>
14
+ 477: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">can_serve</span>(<span class="ruby-identifier">path_info</span>)
15
+ 478: <span class="ruby-identifier">req</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@path</span>,<span class="ruby-identifier">path_info</span>), <span class="ruby-ivar">@path</span>)
16
+ 479:
17
+ 480: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">req</span>.<span class="ruby-identifier">index</span>(<span class="ruby-ivar">@path</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">req</span>
18
+ 481: <span class="ruby-comment cmt"># it exists and it's in the right location</span>
19
+ 482: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span> <span class="ruby-identifier">req</span>
20
+ 483: <span class="ruby-comment cmt"># the request is for a directory</span>
21
+ 484: <span class="ruby-identifier">index</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">req</span>, <span class="ruby-ivar">@index_html</span>)
22
+ 485: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">index</span>
23
+ 486: <span class="ruby-comment cmt"># serve the index</span>
24
+ 487: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">index</span>
25
+ 488: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@listing_allows</span>
26
+ 489: <span class="ruby-comment cmt"># serve the directory</span>
27
+ 490: <span class="ruby-identifier">req</span>
28
+ 491: <span class="ruby-keyword kw">else</span>
29
+ 492: <span class="ruby-comment cmt"># do not serve anything</span>
30
+ 493: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
31
+ 494: <span class="ruby-keyword kw">end</span>
32
+ 495: <span class="ruby-keyword kw">else</span>
33
+ 496: <span class="ruby-comment cmt"># it's a file and it's there</span>
34
+ 497: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">req</span>
35
+ 498: <span class="ruby-keyword kw">end</span>
36
+ 499: <span class="ruby-keyword kw">else</span>
37
+ 500: <span class="ruby-comment cmt"># does not exist or isn't in the right spot</span>
38
+ 501: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
39
+ 502: <span class="ruby-keyword kw">end</span>
40
+ 503: <span class="ruby-keyword kw">end</span></pre>
19
41
  </body>
20
42
  </html>
@@ -5,38 +5,36 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>can_serve (Mongrel::DirHandler)</title>
8
+ <title>send_dir_listing (Mongrel::DirHandler)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 470</span>
14
- 470: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">can_serve</span>(<span class="ruby-identifier">path_info</span>)
15
- 471: <span class="ruby-identifier">req</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@path</span>,<span class="ruby-identifier">path_info</span>), <span class="ruby-ivar">@path</span>)
16
- 472:
17
- 473: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">req</span>.<span class="ruby-identifier">index</span>(<span class="ruby-ivar">@path</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">req</span>
18
- 474: <span class="ruby-comment cmt"># it exists and it's in the right location</span>
19
- 475: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span> <span class="ruby-identifier">req</span>
20
- 476: <span class="ruby-comment cmt"># the request is for a directory</span>
21
- 477: <span class="ruby-identifier">index</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">req</span>, <span class="ruby-ivar">@index_html</span>)
22
- 478: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">index</span>
23
- 479: <span class="ruby-comment cmt"># serve the index</span>
24
- 480: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">index</span>
25
- 481: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@listing_allows</span>
26
- 482: <span class="ruby-comment cmt"># serve the directory</span>
27
- 483: <span class="ruby-identifier">req</span>
28
- 484: <span class="ruby-keyword kw">else</span>
29
- 485: <span class="ruby-comment cmt"># do not serve anything</span>
30
- 486: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
31
- 487: <span class="ruby-keyword kw">end</span>
32
- 488: <span class="ruby-keyword kw">else</span>
33
- 489: <span class="ruby-comment cmt"># it's a file and it's there</span>
34
- 490: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">req</span>
35
- 491: <span class="ruby-keyword kw">end</span>
36
- 492: <span class="ruby-keyword kw">else</span>
37
- 493: <span class="ruby-comment cmt"># does not exist or isn't in the right spot</span>
38
- 494: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
39
- 495: <span class="ruby-keyword kw">end</span>
40
- 496: <span class="ruby-keyword kw">end</span></pre>
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 510</span>
14
+ 510: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_dir_listing</span>(<span class="ruby-identifier">base</span>, <span class="ruby-identifier">dir</span>, <span class="ruby-identifier">response</span>)
15
+ 511: <span class="ruby-comment cmt"># take off any trailing / so the links come out right</span>
16
+ 512: <span class="ruby-identifier">base</span>.<span class="ruby-identifier">chop!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">base</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;/&quot;</span>[<span class="ruby-value">-1</span>]
17
+ 513:
18
+ 514: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@listing_allowed</span>
19
+ 515: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">start</span>(<span class="ruby-value">200</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">head</span>,<span class="ruby-identifier">out</span><span class="ruby-operator">|</span>
20
+ 516: <span class="ruby-identifier">head</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-value str">&quot;text/html&quot;</span>
21
+ 517: <span class="ruby-identifier">out</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Directory Listing&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&quot;</span>
22
+ 518: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">entries</span>(<span class="ruby-identifier">dir</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span>
23
+ 519: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">child</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;.&quot;</span>
24
+ 520:
25
+ 521: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">child</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;..&quot;</span>
26
+ 522: <span class="ruby-identifier">out</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;&lt;a href=\&quot;#{base}/#{child}\&quot;&gt;Up to parent..&lt;/a&gt;&lt;br/&gt;&quot;</span>
27
+ 523: <span class="ruby-keyword kw">else</span>
28
+ 524: <span class="ruby-identifier">out</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;&lt;a href=\&quot;#{base}/#{child}\&quot;&gt;#{child}&lt;/a&gt;&lt;br/&gt;&quot;</span>
29
+ 525: <span class="ruby-keyword kw">end</span>
30
+ 526: <span class="ruby-keyword kw">end</span>
31
+ 527: <span class="ruby-identifier">out</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span>
32
+ 528: <span class="ruby-keyword kw">end</span>
33
+ 529: <span class="ruby-keyword kw">else</span>
34
+ 530: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">start</span>(<span class="ruby-value">403</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">head</span>,<span class="ruby-identifier">out</span><span class="ruby-operator">|</span>
35
+ 531: <span class="ruby-identifier">out</span>.<span class="ruby-identifier">write</span>(<span class="ruby-value str">&quot;Directory listings not allowed&quot;</span>)
36
+ 532: <span class="ruby-keyword kw">end</span>
37
+ 533: <span class="ruby-keyword kw">end</span>
38
+ 534: <span class="ruby-keyword kw">end</span></pre>
41
39
  </body>
42
40
  </html>