thin 0.3.0 → 0.4.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 (51) hide show
  1. data/README +47 -5
  2. data/Rakefile +33 -2
  3. data/doc/rdoc/classes/Kernel.html +182 -0
  4. data/doc/rdoc/classes/Process.html +175 -0
  5. data/doc/rdoc/classes/Thin.html +184 -0
  6. data/doc/rdoc/classes/Thin/CGIWrapper.html +438 -0
  7. data/doc/rdoc/classes/Thin/Cluster.html +392 -0
  8. data/doc/rdoc/classes/Thin/Command.html +221 -0
  9. data/doc/rdoc/classes/Thin/CommandError.html +154 -0
  10. data/doc/rdoc/classes/Thin/Commands.html +145 -0
  11. data/doc/rdoc/classes/Thin/Daemonizable.html +250 -0
  12. data/doc/rdoc/classes/Thin/Daemonizable/ClassMethods.html +203 -0
  13. data/doc/rdoc/classes/Thin/DirHandler.html +250 -0
  14. data/doc/rdoc/classes/Thin/Handler.html +195 -0
  15. data/doc/rdoc/classes/Thin/Headers.html +244 -0
  16. data/doc/rdoc/classes/Thin/InvalidRequest.html +150 -0
  17. data/doc/rdoc/classes/Thin/Logging.html +214 -0
  18. data/doc/rdoc/classes/Thin/RailsHandler.html +234 -0
  19. data/doc/rdoc/classes/Thin/RailsServer.html +175 -0
  20. data/doc/rdoc/classes/Thin/Request.html +379 -0
  21. data/doc/rdoc/classes/Thin/Response.html +311 -0
  22. data/doc/rdoc/classes/Thin/Server.html +381 -0
  23. data/doc/rdoc/created.rid +1 -0
  24. data/doc/rdoc/files/README.html +260 -0
  25. data/doc/rdoc/files/bin/thin.html +188 -0
  26. data/doc/rdoc/files/bin/thin_cluster.html +175 -0
  27. data/doc/rdoc/files/lib/thin/cgi_rb.html +263 -0
  28. data/doc/rdoc/files/lib/thin/cluster_rb.html +263 -0
  29. data/doc/rdoc/files/lib/thin/command_rb.html +263 -0
  30. data/doc/rdoc/files/lib/thin/consts_rb.html +263 -0
  31. data/doc/rdoc/files/lib/thin/daemonizing_rb.html +263 -0
  32. data/doc/rdoc/files/lib/thin/handler_rb.html +263 -0
  33. data/doc/rdoc/files/lib/thin/headers_rb.html +263 -0
  34. data/doc/rdoc/files/lib/thin/logging_rb.html +263 -0
  35. data/doc/rdoc/files/lib/thin/mime_types_rb.html +263 -0
  36. data/doc/rdoc/files/lib/thin/rails_rb.html +263 -0
  37. data/doc/rdoc/files/lib/thin/recipes_rb.html +171 -0
  38. data/doc/rdoc/files/lib/thin/request_rb.html +171 -0
  39. data/doc/rdoc/files/lib/thin/response_rb.html +171 -0
  40. data/doc/rdoc/files/lib/thin/server_rb.html +171 -0
  41. data/doc/rdoc/files/lib/thin/statuses_rb.html +171 -0
  42. data/doc/rdoc/files/lib/thin/version_rb.html +171 -0
  43. data/doc/rdoc/index.html +10 -0
  44. data/doc/rdoc/logo.gif +0 -0
  45. data/doc/rdoc/rdoc-style.css +86 -0
  46. data/lib/thin/commands/cluster/config.rb +2 -0
  47. data/lib/thin/consts.rb +4 -0
  48. data/lib/thin/request.rb +30 -11
  49. data/lib/thin/server.rb +1 -1
  50. data/lib/thin/version.rb +1 -1
  51. metadata +52 -1
@@ -0,0 +1,381 @@
1
+
2
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3
+ <html>
4
+ <head>
5
+ <title>
6
+ thin &raquo; Class: Thin::Server
7
+ </title>
8
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
10
+ <script language="JavaScript" type="text/javascript">
11
+ // <![CDATA[
12
+
13
+ function toggleSource( id )
14
+ {
15
+ var elem
16
+ var link
17
+
18
+ if( document.getElementById )
19
+ {
20
+ elem = document.getElementById( id )
21
+ link = document.getElementById( "l_" + id )
22
+ }
23
+ else if ( document.all )
24
+ {
25
+ elem = eval( "document.all." + id )
26
+ link = eval( "document.all.l_" + id )
27
+ }
28
+ else
29
+ return false;
30
+
31
+ if( elem.style.display == "block" )
32
+ {
33
+ elem.style.display = "none"
34
+ link.innerHTML = "show source"
35
+ }
36
+ else
37
+ {
38
+ elem.style.display = "block"
39
+ link.innerHTML = "hide source"
40
+ }
41
+ }
42
+
43
+ function openCode( url )
44
+ {
45
+ window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
46
+ }
47
+ // ]]>
48
+ </script>
49
+ </head>
50
+ <body>
51
+ <ul id="menu">
52
+ <li><a href="/thin/">home</a></li>
53
+ <li><a href="/thin/doc/">doc</a></li>
54
+ <li><a href="/thin/trac.fcgi/timeline">timeline</a></li>
55
+ <li><a href="/thin/trac.fcgi/browser">code</a></li>
56
+ <li><a href="/thin/trac.fcgi/report">tickets</a></li>
57
+ <li><a href="/thin/trac.fcgi/newticket">new ticket</a></li>
58
+ </ul>
59
+ <div id="sidebar">
60
+ <h2>Files</h2>
61
+ <ul class="list">
62
+ <li><a href="../../files/README.html" value="File: README">README</a></li>
63
+ <li><a href="../../files/lib/thin/cgi_rb.html" value="File: cgi.rb">lib/thin/cgi.rb</a></li>
64
+ <li><a href="../../files/lib/thin/cluster_rb.html" value="File: cluster.rb">lib/thin/cluster.rb</a></li>
65
+ <li><a href="../../files/lib/thin/command_rb.html" value="File: command.rb">lib/thin/command.rb</a></li>
66
+ <li><a href="../../files/lib/thin/consts_rb.html" value="File: consts.rb">lib/thin/consts.rb</a></li>
67
+ <li><a href="../../files/lib/thin/daemonizing_rb.html" value="File: daemonizing.rb">lib/thin/daemonizing.rb</a></li>
68
+ <li><a href="../../files/lib/thin/handler_rb.html" value="File: handler.rb">lib/thin/handler.rb</a></li>
69
+ <li><a href="../../files/lib/thin/headers_rb.html" value="File: headers.rb">lib/thin/headers.rb</a></li>
70
+ <li><a href="../../files/lib/thin/logging_rb.html" value="File: logging.rb">lib/thin/logging.rb</a></li>
71
+ <li><a href="../../files/lib/thin/mime_types_rb.html" value="File: mime_types.rb">lib/thin/mime_types.rb</a></li>
72
+ <li><a href="../../files/lib/thin/rails_rb.html" value="File: rails.rb">lib/thin/rails.rb</a></li>
73
+ <li><a href="../../files/lib/thin/recipes_rb.html" value="File: recipes.rb">lib/thin/recipes.rb</a></li>
74
+ <li><a href="../../files/lib/thin/request_rb.html" value="File: request.rb">lib/thin/request.rb</a></li>
75
+ <li><a href="../../files/lib/thin/response_rb.html" value="File: response.rb">lib/thin/response.rb</a></li>
76
+ <li><a href="../../files/lib/thin/server_rb.html" value="File: server.rb">lib/thin/server.rb</a></li>
77
+ <li><a href="../../files/lib/thin/statuses_rb.html" value="File: statuses.rb">lib/thin/statuses.rb</a></li>
78
+ <li><a href="../../files/lib/thin/version_rb.html" value="File: version.rb">lib/thin/version.rb</a></li>
79
+ <li><a href="../../files/bin/thin.html" value="File: thin">bin/thin</a></li>
80
+ <li><a href="../../files/bin/thin_cluster.html" value="File: thin_cluster">bin/thin_cluster</a></li>
81
+ </ul>
82
+
83
+ <h2>Classes</h2>
84
+ <ul class="list">
85
+ <li><a href="../../classes/Thin.html" title="Module: Thin">Thin</a></li>
86
+ <li><a href="../../classes/Thin/Commands.html" title="Module: Thin::Commands">Thin::Commands</a></li>
87
+ <li><a href="../../classes/Thin/Daemonizable.html" title="Module: Thin::Daemonizable">Thin::Daemonizable</a></li>
88
+ <li><a href="../../classes/Thin/Daemonizable/ClassMethods.html" title="Module: Thin::Daemonizable::ClassMethods">Thin::Daemonizable::ClassMethods</a></li>
89
+ <li><a href="../../classes/Thin/VERSION.html" title="Module: Thin::VERSION">Thin::VERSION</a></li>
90
+ <li><a href="../../classes/Thin/Logging.html" title="Module: Thin::Logging">Thin::Logging</a></li>
91
+ <li><a href="../../classes/Thin/DirHandler.html" title="Class: Thin::DirHandler">Thin::DirHandler</a></li>
92
+ <li><a href="../../classes/Thin/InvalidRequest.html" title="Class: Thin::InvalidRequest">Thin::InvalidRequest</a></li>
93
+ <li><a href="../../classes/Thin/CGIWrapper.html" title="Class: Thin::CGIWrapper">Thin::CGIWrapper</a></li>
94
+ <li><a href="../../classes/Thin/Command.html" title="Class: Thin::Command">Thin::Command</a></li>
95
+ <li><a href="../../classes/Thin/Response.html" title="Class: Thin::Response">Thin::Response</a></li>
96
+ <li><a href="../../classes/Thin/Headers.html" title="Class: Thin::Headers">Thin::Headers</a></li>
97
+ <li><a href="../../classes/Thin/Server.html" title="Class: Thin::Server">Thin::Server</a></li>
98
+ <li><a href="../../classes/Thin/CommandError.html" title="Class: Thin::CommandError">Thin::CommandError</a></li>
99
+ <li><a href="../../classes/Thin/Request.html" title="Class: Thin::Request">Thin::Request</a></li>
100
+ <li><a href="../../classes/Thin/RailsServer.html" title="Class: Thin::RailsServer">Thin::RailsServer</a></li>
101
+ <li><a href="../../classes/Thin/Cluster.html" title="Class: Thin::Cluster">Thin::Cluster</a></li>
102
+ <li><a href="../../classes/Thin/RailsHandler.html" title="Class: Thin::RailsHandler">Thin::RailsHandler</a></li>
103
+ <li><a href="../../classes/Thin/Handler.html" title="Class: Thin::Handler">Thin::Handler</a></li>
104
+ <li><a href="../../classes/Process.html" title="Module: Process">Process</a></li>
105
+ <li><a href="../../classes/Kernel.html" title="Module: Kernel">Kernel</a></li>
106
+ </ul>
107
+ </div>
108
+ <div id="container">
109
+ <div id="header">
110
+ <a href="/thin/" title="Home">
111
+ <img id="logo" src="../../logo.gif" />
112
+ </a>
113
+ <h2 id="tag_line">A fast and very simple Ruby web server</h2>
114
+ </div>
115
+
116
+ <div id="content">
117
+ <h2>Class: Thin::Server</h2>
118
+
119
+
120
+ <div id="Thin::Server" class="page_shade">
121
+ <div class="page">
122
+ <h3>Class Thin::Server &lt; <a href="Handler.html">Object</a></h3>
123
+
124
+ <span class="path">(in files
125
+ <a href="../../files/lib/thin/server_rb.html">lib/thin/server.rb</a>
126
+ )</span>
127
+
128
+ <p>
129
+ The <a href="../Thin.html">Thin</a> HTTP server used to served request. It
130
+ listen for incoming request on a given port and forward all request to all
131
+ the handlers in the order they were registered. Based on HTTP 1.1 protocol
132
+ specs <a
133
+ href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">www.w3.org/Protocols/rfc2616/rfc2616.html</a>
134
+ </p>
135
+
136
+
137
+
138
+
139
+ <h4>Includes</h4>
140
+ <ul>
141
+ <li><a href="Logging.html">Logging</a></li>
142
+ <li><a href="Daemonizable.html">Daemonizable</a></li>
143
+ </ul>
144
+
145
+ <h2 class="ruled">Methods</h2>
146
+ <h4 class="ruled">
147
+ <span class="method-type" title="Public Class method">Public Class</span>
148
+ <strong><a name="M000041" href="#M000041" title="Permalink to Public Class method: new">new(host, port, *handlers)</a></strong>
149
+ </h4>
150
+
151
+ <p>
152
+ Creates a <a href="Server.html#M000041">new</a> server binded to
153
+ <tt>host:port</tt> that will pass request to <tt>handlers</tt>.
154
+ </p>
155
+
156
+ <div class="sourcecode">
157
+ <p class="source-link">[ <a href="javascript:toggleSource('M000041_source')" id="l_M000041_source">show source</a> ]</p>
158
+ <div id="M000041_source" class="dyn-source">
159
+ <pre>
160
+ <span class="ruby-comment cmt"># File lib/thin/server.rb, line 25</span>
161
+ 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">handlers</span>)
162
+ 26: <span class="ruby-ivar">@host</span> = <span class="ruby-identifier">host</span>
163
+ 27: <span class="ruby-ivar">@port</span> = <span class="ruby-identifier">port</span>
164
+ 28: <span class="ruby-ivar">@handlers</span> = <span class="ruby-identifier">handlers</span>
165
+ 29: <span class="ruby-ivar">@timeout</span> = <span class="ruby-value">60</span> <span class="ruby-comment cmt"># sec, max time to read and parse a request</span>
166
+ 30: <span class="ruby-ivar">@trace</span> = <span class="ruby-keyword kw">false</span>
167
+ 31:
168
+ 32: <span class="ruby-ivar">@stop</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-comment cmt"># true is server is stopped</span>
169
+ 33: <span class="ruby-ivar">@processing</span> = <span class="ruby-keyword kw">false</span> <span class="ruby-comment cmt"># true is processing a request</span>
170
+ 34:
171
+ 35: <span class="ruby-ivar">@socket</span> = <span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>)
172
+ 36: <span class="ruby-keyword kw">end</span>
173
+ </pre>
174
+ </div>
175
+ </div>
176
+ <h4 class="ruled">
177
+ <span class="method-type" title="Public Instance method">Public Instance</span>
178
+ <strong><a name="M000044" href="#M000044" title="Permalink to Public Instance method: listen!">listen!()</a></strong>
179
+ </h4>
180
+
181
+ <p>
182
+ Start listening for connections
183
+ </p>
184
+
185
+ <div class="sourcecode">
186
+ <p class="source-link">[ <a href="javascript:toggleSource('M000044_source')" id="l_M000044_source">show source</a> ]</p>
187
+ <div id="M000044_source" class="dyn-source">
188
+ <pre>
189
+ <span class="ruby-comment cmt"># File lib/thin/server.rb, line 56</span>
190
+ 56: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">listen!</span>
191
+ 57: <span class="ruby-ivar">@stop</span> = <span class="ruby-keyword kw">false</span>
192
+ 58: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'INT'</span>) <span class="ruby-keyword kw">do</span>
193
+ 59: <span class="ruby-identifier">log</span> <span class="ruby-value str">'&gt;&gt; Caught INT signal, stopping ...'</span>
194
+ 60: <span class="ruby-identifier">stop</span>
195
+ 61: <span class="ruby-keyword kw">end</span>
196
+ 62:
197
+ 63: <span class="ruby-identifier">log</span> <span class="ruby-node">&quot;&gt;&gt; Listening on #{host}:#{port}, CTRL+C to stop&quot;</span>
198
+ 64: <span class="ruby-keyword kw">until</span> <span class="ruby-ivar">@stop</span>
199
+ 65: <span class="ruby-ivar">@processing</span> = <span class="ruby-keyword kw">false</span>
200
+ 66: <span class="ruby-identifier">client</span> = <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">accept</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
201
+ 67: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">closed?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">client</span>.<span class="ruby-identifier">nil?</span>
202
+ 68: <span class="ruby-ivar">@processing</span> = <span class="ruby-keyword kw">true</span>
203
+ 69: <span class="ruby-identifier">process</span>(<span class="ruby-identifier">client</span>)
204
+ 70: <span class="ruby-keyword kw">end</span>
205
+ 71: <span class="ruby-keyword kw">ensure</span>
206
+ 72: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">closed?</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
207
+ 73: <span class="ruby-keyword kw">end</span>
208
+ </pre>
209
+ </div>
210
+ </div>
211
+ <h4 class="ruled">
212
+ <span class="method-type" title="Public Instance method">Public Instance</span>
213
+ <strong><a name="M000045" href="#M000045" title="Permalink to Public Instance method: process">process(client)</a></strong>
214
+ </h4>
215
+
216
+ <p>
217
+ <a href="../Process.html">Process</a> one request from a client
218
+ </p>
219
+
220
+ <div class="sourcecode">
221
+ <p class="source-link">[ <a href="javascript:toggleSource('M000045_source')" id="l_M000045_source">show source</a> ]</p>
222
+ <div id="M000045_source" class="dyn-source">
223
+ <pre>
224
+ <span class="ruby-comment cmt"># File lib/thin/server.rb, line 76</span>
225
+ 76: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>(<span class="ruby-identifier">client</span>)
226
+ 77: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">client</span>.<span class="ruby-identifier">eof?</span>
227
+ 78:
228
+ 79: <span class="ruby-identifier">trace</span> { <span class="ruby-value str">'Request started'</span>.<span class="ruby-identifier">center</span>(<span class="ruby-value">80</span>, <span class="ruby-value str">'='</span>) }
229
+ 80:
230
+ 81: <span class="ruby-identifier">request</span> = <span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>
231
+ 82: <span class="ruby-identifier">response</span> = <span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
232
+ 83:
233
+ 84: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">trace</span> = <span class="ruby-ivar">@trace</span>
234
+ 85: <span class="ruby-identifier">trace</span> { <span class="ruby-value str">&quot;&gt;&gt; Tracing request parsing ... &quot;</span> }
235
+ 86:
236
+ 87: <span class="ruby-comment cmt"># Parse the request checking for timeout to prevent DOS attacks</span>
237
+ 88: <span class="ruby-constant">Timeout</span>.<span class="ruby-identifier">timeout</span>(<span class="ruby-ivar">@timeout</span>) { <span class="ruby-identifier">request</span>.<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">client</span>) }
238
+ 89: <span class="ruby-identifier">trace</span> { <span class="ruby-identifier">request</span>.<span class="ruby-identifier">raw</span> }
239
+ 90:
240
+ 91: <span class="ruby-comment cmt"># Add client info to the request env</span>
241
+ 92: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-value str">'REMOTE_ADDR'</span>] = <span class="ruby-identifier">client</span>.<span class="ruby-identifier">peeraddr</span>.<span class="ruby-identifier">last</span>
242
+ 93:
243
+ 94: <span class="ruby-comment cmt"># Add server info to the request env</span>
244
+ 95: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-value str">'SERVER_SOFTWARE'</span>] = <span class="ruby-constant">SERVER</span>
245
+ 96: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>[<span class="ruby-value str">'SERVER_PORT'</span>] = <span class="ruby-ivar">@port</span>.<span class="ruby-identifier">to_s</span>
246
+ 97:
247
+ 98: <span class="ruby-identifier">served</span> = <span class="ruby-keyword kw">false</span>
248
+ 99: <span class="ruby-ivar">@handlers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">handler</span><span class="ruby-operator">|</span>
249
+ 100: <span class="ruby-identifier">served</span> = <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">response</span>)
250
+ 101: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">served</span>
251
+ 102: <span class="ruby-keyword kw">end</span>
252
+ 103:
253
+ 104: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">served</span>
254
+ 105: <span class="ruby-identifier">trace</span> { <span class="ruby-value str">&quot;&gt;&gt; Sending response:\n&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">to_s</span> }
255
+ 106: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">client</span>
256
+ 107: <span class="ruby-keyword kw">else</span>
257
+ 108: <span class="ruby-identifier">client</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">ERROR_404_RESPONSE</span>
258
+ 109: <span class="ruby-keyword kw">end</span>
259
+ 110:
260
+ 111: <span class="ruby-identifier">trace</span> { <span class="ruby-value str">'Request finished'</span>.<span class="ruby-identifier">center</span>(<span class="ruby-value">80</span>, <span class="ruby-value str">'='</span>) }
261
+ 112:
262
+ 113: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">EOFError</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNRESET</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EPIPE</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EINVAL</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EBADF</span>
263
+ 114: <span class="ruby-comment cmt"># Can't do anything sorry, closing the socket in the ensure block</span>
264
+ 115: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">InvalidRequest</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
265
+ 116: <span class="ruby-identifier">log</span> <span class="ruby-node">&quot;Invalid request: #{e.message}&quot;</span>
266
+ 117: <span class="ruby-identifier">trace</span> { <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>) }
267
+ 118: <span class="ruby-identifier">client</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">ERROR_400_RESPONSE</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
268
+ 119: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Object</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
269
+ 120: <span class="ruby-identifier">log</span> <span class="ruby-node">&quot;Unexpected error while processing request: #{e.message}&quot;</span>
270
+ 121: <span class="ruby-identifier">log</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>)
271
+ 122: <span class="ruby-keyword kw">ensure</span>
272
+ 123: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">request</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
273
+ 124: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">response</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
274
+ 125: <span class="ruby-identifier">client</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">client</span>.<span class="ruby-identifier">closed?</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
275
+ 126: <span class="ruby-keyword kw">end</span>
276
+ </pre>
277
+ </div>
278
+ </div>
279
+ <h4 class="ruled">
280
+ <span class="method-type" title="Public Instance method">Public Instance</span>
281
+ <strong><a name="M000042" href="#M000042" title="Permalink to Public Instance method: start">start()</a></strong>
282
+ </h4>
283
+
284
+ <p>
285
+ Starts the handlers.
286
+ </p>
287
+
288
+ <div class="sourcecode">
289
+ <p class="source-link">[ <a href="javascript:toggleSource('M000042_source')" id="l_M000042_source">show source</a> ]</p>
290
+ <div id="M000042_source" class="dyn-source">
291
+ <pre>
292
+ <span class="ruby-comment cmt"># File lib/thin/server.rb, line 39</span>
293
+ 39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>
294
+ 40: <span class="ruby-identifier">log</span> <span class="ruby-node">&quot;&gt;&gt; Thin web server (v#{VERSION::STRING})&quot;</span>
295
+ 41: <span class="ruby-identifier">trace</span> <span class="ruby-value str">&quot;&gt;&gt; Tracing ON&quot;</span>
296
+ 42:
297
+ 43: <span class="ruby-ivar">@handlers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">handler</span><span class="ruby-operator">|</span>
298
+ 44: <span class="ruby-identifier">log</span> <span class="ruby-node">&quot;&gt;&gt; Starting #{handler} ...&quot;</span>
299
+ 45: <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">start</span>
300
+ 46: <span class="ruby-keyword kw">end</span>
301
+ 47: <span class="ruby-keyword kw">end</span>
302
+ </pre>
303
+ </div>
304
+ </div>
305
+ <h4 class="ruled">
306
+ <span class="method-type" title="Public Instance method">Public Instance</span>
307
+ <strong><a name="M000043" href="#M000043" title="Permalink to Public Instance method: start!">start!()</a></strong>
308
+ </h4>
309
+
310
+ <p>
311
+ Start the server and listen for connections
312
+ </p>
313
+
314
+ <div class="sourcecode">
315
+ <p class="source-link">[ <a href="javascript:toggleSource('M000043_source')" id="l_M000043_source">show source</a> ]</p>
316
+ <div id="M000043_source" class="dyn-source">
317
+ <pre>
318
+ <span class="ruby-comment cmt"># File lib/thin/server.rb, line 50</span>
319
+ 50: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start!</span>
320
+ 51: <span class="ruby-identifier">start</span>
321
+ 52: <span class="ruby-identifier">listen!</span>
322
+ 53: <span class="ruby-keyword kw">end</span>
323
+ </pre>
324
+ </div>
325
+ </div>
326
+ <h4 class="ruled">
327
+ <span class="method-type" title="Public Instance method">Public Instance</span>
328
+ <strong><a name="M000046" href="#M000046" title="Permalink to Public Instance method: stop">stop()</a></strong>
329
+ </h4>
330
+
331
+ <p>
332
+ Stop the server from accepting <a href="Server.html#M000041">new</a>
333
+ request. If a request is processing, wait for this to finish and shutdown
334
+ the server.
335
+ </p>
336
+
337
+ <div class="sourcecode">
338
+ <p class="source-link">[ <a href="javascript:toggleSource('M000046_source')" id="l_M000046_source">show source</a> ]</p>
339
+ <div id="M000046_source" class="dyn-source">
340
+ <pre>
341
+ <span class="ruby-comment cmt"># File lib/thin/server.rb, line 131</span>
342
+ 131: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
343
+ 132: <span class="ruby-ivar">@stop</span> = <span class="ruby-keyword kw">true</span>
344
+ 133: <span class="ruby-identifier">stop!</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@processing</span> <span class="ruby-comment cmt"># Not processing a request, so we can stop now</span>
345
+ 134: <span class="ruby-keyword kw">end</span>
346
+ </pre>
347
+ </div>
348
+ </div>
349
+ <h4 class="ruled">
350
+ <span class="method-type" title="Public Instance method">Public Instance</span>
351
+ <strong><a name="M000047" href="#M000047" title="Permalink to Public Instance method: stop!">stop!()</a></strong>
352
+ </h4>
353
+
354
+ <p>
355
+ Force the server to <a href="Server.html#M000046">stop</a> right now!
356
+ </p>
357
+
358
+ <div class="sourcecode">
359
+ <p class="source-link">[ <a href="javascript:toggleSource('M000047_source')" id="l_M000047_source">show source</a> ]</p>
360
+ <div id="M000047_source" class="dyn-source">
361
+ <pre>
362
+ <span class="ruby-comment cmt"># File lib/thin/server.rb, line 137</span>
363
+ 137: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop!</span>
364
+ 138: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># break the accept loop by closing the socket</span>
365
+ 139: <span class="ruby-keyword kw">end</span>
366
+ </pre>
367
+ </div>
368
+ </div>
369
+
370
+ </div>
371
+ </div>
372
+
373
+
374
+ </div>
375
+ </div>
376
+ <div id="footer">
377
+ <hr />
378
+ &copy; <a href="http://macournoyer.com">Marc-Andr&eacute; Cournoyer</a>
379
+ </div>
380
+ </body>
381
+ </html>
@@ -0,0 +1 @@
1
+ Mon, 03 Dec 2007 23:40:27 -0500
@@ -0,0 +1,260 @@
1
+
2
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3
+ <html>
4
+ <head>
5
+ <title>
6
+ thin &raquo; File: README
7
+ </title>
8
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
10
+ <script language="JavaScript" type="text/javascript">
11
+ // <![CDATA[
12
+
13
+ function toggleSource( id )
14
+ {
15
+ var elem
16
+ var link
17
+
18
+ if( document.getElementById )
19
+ {
20
+ elem = document.getElementById( id )
21
+ link = document.getElementById( "l_" + id )
22
+ }
23
+ else if ( document.all )
24
+ {
25
+ elem = eval( "document.all." + id )
26
+ link = eval( "document.all.l_" + id )
27
+ }
28
+ else
29
+ return false;
30
+
31
+ if( elem.style.display == "block" )
32
+ {
33
+ elem.style.display = "none"
34
+ link.innerHTML = "show source"
35
+ }
36
+ else
37
+ {
38
+ elem.style.display = "block"
39
+ link.innerHTML = "hide source"
40
+ }
41
+ }
42
+
43
+ function openCode( url )
44
+ {
45
+ window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
46
+ }
47
+ // ]]>
48
+ </script>
49
+ </head>
50
+ <body>
51
+ <ul id="menu">
52
+ <li><a href="/thin/">home</a></li>
53
+ <li><a href="/thin/doc/">doc</a></li>
54
+ <li><a href="/thin/trac.fcgi/timeline">timeline</a></li>
55
+ <li><a href="/thin/trac.fcgi/browser">code</a></li>
56
+ <li><a href="/thin/trac.fcgi/report">tickets</a></li>
57
+ <li><a href="/thin/trac.fcgi/newticket">new ticket</a></li>
58
+ </ul>
59
+ <div id="sidebar">
60
+ <h2>Files</h2>
61
+ <ul class="list">
62
+ <li><a href="../files/README.html" value="File: README">README</a></li>
63
+ <li><a href="../files/lib/thin/cgi_rb.html" value="File: cgi.rb">lib/thin/cgi.rb</a></li>
64
+ <li><a href="../files/lib/thin/cluster_rb.html" value="File: cluster.rb">lib/thin/cluster.rb</a></li>
65
+ <li><a href="../files/lib/thin/command_rb.html" value="File: command.rb">lib/thin/command.rb</a></li>
66
+ <li><a href="../files/lib/thin/consts_rb.html" value="File: consts.rb">lib/thin/consts.rb</a></li>
67
+ <li><a href="../files/lib/thin/daemonizing_rb.html" value="File: daemonizing.rb">lib/thin/daemonizing.rb</a></li>
68
+ <li><a href="../files/lib/thin/handler_rb.html" value="File: handler.rb">lib/thin/handler.rb</a></li>
69
+ <li><a href="../files/lib/thin/headers_rb.html" value="File: headers.rb">lib/thin/headers.rb</a></li>
70
+ <li><a href="../files/lib/thin/logging_rb.html" value="File: logging.rb">lib/thin/logging.rb</a></li>
71
+ <li><a href="../files/lib/thin/mime_types_rb.html" value="File: mime_types.rb">lib/thin/mime_types.rb</a></li>
72
+ <li><a href="../files/lib/thin/rails_rb.html" value="File: rails.rb">lib/thin/rails.rb</a></li>
73
+ <li><a href="../files/lib/thin/recipes_rb.html" value="File: recipes.rb">lib/thin/recipes.rb</a></li>
74
+ <li><a href="../files/lib/thin/request_rb.html" value="File: request.rb">lib/thin/request.rb</a></li>
75
+ <li><a href="../files/lib/thin/response_rb.html" value="File: response.rb">lib/thin/response.rb</a></li>
76
+ <li><a href="../files/lib/thin/server_rb.html" value="File: server.rb">lib/thin/server.rb</a></li>
77
+ <li><a href="../files/lib/thin/statuses_rb.html" value="File: statuses.rb">lib/thin/statuses.rb</a></li>
78
+ <li><a href="../files/lib/thin/version_rb.html" value="File: version.rb">lib/thin/version.rb</a></li>
79
+ <li><a href="../files/bin/thin.html" value="File: thin">bin/thin</a></li>
80
+ <li><a href="../files/bin/thin_cluster.html" value="File: thin_cluster">bin/thin_cluster</a></li>
81
+ </ul>
82
+
83
+ <h2>Classes</h2>
84
+ <ul class="list">
85
+ <li><a href="../classes/Thin.html" title="Module: Thin">Thin</a></li>
86
+ <li><a href="../classes/Thin/Commands.html" title="Module: Thin::Commands">Thin::Commands</a></li>
87
+ <li><a href="../classes/Thin/Daemonizable.html" title="Module: Thin::Daemonizable">Thin::Daemonizable</a></li>
88
+ <li><a href="../classes/Thin/Daemonizable/ClassMethods.html" title="Module: Thin::Daemonizable::ClassMethods">Thin::Daemonizable::ClassMethods</a></li>
89
+ <li><a href="../classes/Thin/VERSION.html" title="Module: Thin::VERSION">Thin::VERSION</a></li>
90
+ <li><a href="../classes/Thin/Logging.html" title="Module: Thin::Logging">Thin::Logging</a></li>
91
+ <li><a href="../classes/Thin/DirHandler.html" title="Class: Thin::DirHandler">Thin::DirHandler</a></li>
92
+ <li><a href="../classes/Thin/InvalidRequest.html" title="Class: Thin::InvalidRequest">Thin::InvalidRequest</a></li>
93
+ <li><a href="../classes/Thin/CGIWrapper.html" title="Class: Thin::CGIWrapper">Thin::CGIWrapper</a></li>
94
+ <li><a href="../classes/Thin/Command.html" title="Class: Thin::Command">Thin::Command</a></li>
95
+ <li><a href="../classes/Thin/Response.html" title="Class: Thin::Response">Thin::Response</a></li>
96
+ <li><a href="../classes/Thin/Headers.html" title="Class: Thin::Headers">Thin::Headers</a></li>
97
+ <li><a href="../classes/Thin/Server.html" title="Class: Thin::Server">Thin::Server</a></li>
98
+ <li><a href="../classes/Thin/CommandError.html" title="Class: Thin::CommandError">Thin::CommandError</a></li>
99
+ <li><a href="../classes/Thin/Request.html" title="Class: Thin::Request">Thin::Request</a></li>
100
+ <li><a href="../classes/Thin/RailsServer.html" title="Class: Thin::RailsServer">Thin::RailsServer</a></li>
101
+ <li><a href="../classes/Thin/Cluster.html" title="Class: Thin::Cluster">Thin::Cluster</a></li>
102
+ <li><a href="../classes/Thin/RailsHandler.html" title="Class: Thin::RailsHandler">Thin::RailsHandler</a></li>
103
+ <li><a href="../classes/Thin/Handler.html" title="Class: Thin::Handler">Thin::Handler</a></li>
104
+ <li><a href="../classes/Process.html" title="Module: Process">Process</a></li>
105
+ <li><a href="../classes/Kernel.html" title="Module: Kernel">Kernel</a></li>
106
+ </ul>
107
+ </div>
108
+ <div id="container">
109
+ <div id="header">
110
+ <a href="/thin/" title="Home">
111
+ <img id="logo" src="../logo.gif" />
112
+ </a>
113
+ <h2 id="tag_line">A fast and very simple Ruby web server</h2>
114
+ </div>
115
+
116
+ <div id="content">
117
+ <h2>File: README</h2>
118
+
119
+ <div id="README" class="page_shade">
120
+ <div class="page">
121
+ <div class="header">
122
+ <div class="path">README / Mon Dec 03 23:24:17 -0500 2007</div>
123
+ </div>
124
+
125
+ <h2><a href="../classes/Thin.html">Thin</a></h2>
126
+ <p>
127
+ Tiny, fast &amp; funny HTTP server
128
+ </p>
129
+ <p>
130
+ <a href="../classes/Thin.html">Thin</a> is a web server written entirely in
131
+ Ruby in the simplest way possible. It does as little as possible to serve
132
+ your Rails application, which makes it one of the fastest Rails server out
133
+ there.
134
+ </p>
135
+ <h3>Installation</h3>
136
+ <p>
137
+ For the latest stable version:
138
+ </p>
139
+ <pre>
140
+ sudo gem install thin
141
+ </pre>
142
+ <p>
143
+ For the risky but so much cooler alpha version:
144
+ </p>
145
+ <pre>
146
+ sudo gem install thin --source http://code.macournoyer.com
147
+ </pre>
148
+ <p>
149
+ Or from source:
150
+ </p>
151
+ <pre>
152
+ svn co http://code.macournoyer.com/svn/thin/trunk thin
153
+ cd thin
154
+ rake install
155
+ </pre>
156
+ <h3>Usage</h3>
157
+ <p>
158
+ In your Rails app directory:
159
+ </p>
160
+ <pre>
161
+ thin start
162
+ </pre>
163
+ <p>
164
+ See <a
165
+ href="http://code.macournoyer.com/thin/doc/files/bin/thin.html">code.macournoyer.com/thin/doc/files/bin/thin.html</a>
166
+ </p>
167
+ <h3>Deployment</h3>
168
+ <p>
169
+ To deploy your Rails application using a cluster of thin servers. You can
170
+ start it with:
171
+ </p>
172
+ <pre>
173
+ thin_cluster start
174
+ </pre>
175
+ <p>
176
+ To use the Capistrano recipes, add this to your Capfile:
177
+ </p>
178
+ <pre>
179
+ require 'thin'
180
+ require 'thin/recipes'
181
+ </pre>
182
+ <p>
183
+ and create a config file using:
184
+ </p>
185
+ <pre>
186
+ thin_cluster config
187
+ </pre>
188
+ <p>
189
+ See <a
190
+ href="http://code.macournoyer.com/thin/doc/files/bin/thin_cluster.html">code.macournoyer.com/thin/doc/files/bin/thin_cluster.html</a>
191
+ </p>
192
+ <h3>Security</h3>
193
+ <p>
194
+ <a href="../classes/Thin.html">Thin</a> should never be used facing the
195
+ internet directly, it should always be hidden behind a proxy server!
196
+ </p>
197
+ <p>
198
+ <a href="../classes/Thin.html">Thin</a> is faster because it doesn&#8216;t
199
+ do a lot of things that other Ruby web servers do (use threads, validate
200
+ the body length, be very strict about the request format, etc.) but that a
201
+ good proxy server do very well (and a lot faster then any Ruby code could
202
+ possibly do). So it is very important that you setup you proxy server
203
+ correctly in order to secure <a href="../classes/Thin.html">Thin</a> from
204
+ potential attacks.
205
+ </p>
206
+ <p>
207
+ Nginx comes with everything you need and can be used securely out of the
208
+ box with thin.
209
+ </p>
210
+ <p>
211
+ Apache mod_proxy is not secure because it doesn&#8216;t cache the request
212
+ before sending it to the backend, which open your server to easy DoS
213
+ attacks. You need to install mod_accel (<a
214
+ href="http://sysoev.ru/en">sysoev.ru/en</a>/) to make mod_proxy behave like
215
+ Nginx on that side.
216
+ </p>
217
+ <h3>License</h3>
218
+ <p>
219
+ Ruby License, <a
220
+ href="http://www.ruby-lang.org/en/LICENSE.txt">www.ruby-lang.org/en/LICENSE.txt</a>.
221
+ </p>
222
+ <h3>Credits</h3>
223
+ <p>
224
+ Lots of the code was inspired (or stolen entirely) from Mongrel <a
225
+ href="http://mongrel.rubyforge.org">mongrel.rubyforge.org</a> by Zed Shaw.
226
+ Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
227
+ &lt;zedshaw at zedshaw dot com&gt; You can redistribute it and/or modify it
228
+ under either the terms of the GPL.
229
+ </p>
230
+ <p>
231
+ transat/parser.rb was taken from Piston source code. Copyright (c) 2006
232
+ Francois Beausoleil &lt;francois@teksol.info&gt;
233
+ </p>
234
+ <p>
235
+ <a href="../classes/Thin.html">Thin</a> is copyright Marc-Andre Cournoyer
236
+ &lt;macournoyer@gmail.com&gt;
237
+ </p>
238
+ <p>
239
+ Please report any bug at <a
240
+ href="http://code.macournoyer.com/thin/trac.fcgi/newticket">code.macournoyer.com/thin/trac.fcgi/newticket</a>
241
+ </p>
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+ </div>
250
+ </div>
251
+
252
+
253
+ </div>
254
+ </div>
255
+ <div id="footer">
256
+ <hr />
257
+ &copy; <a href="http://macournoyer.com">Marc-Andr&eacute; Cournoyer</a>
258
+ </div>
259
+ </body>
260
+ </html>