mongrel 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/COPYING +504 -0
  2. data/LICENSE +504 -0
  3. data/README +117 -0
  4. data/Rakefile +30 -0
  5. data/doc/rdoc/classes/Mongrel.html +144 -0
  6. data/doc/rdoc/classes/Mongrel/Error404Handler.html +171 -0
  7. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000023.html +18 -0
  8. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000024.html +18 -0
  9. data/doc/rdoc/classes/Mongrel/HeaderOut.html +167 -0
  10. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000013.html +18 -0
  11. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000014.html +21 -0
  12. data/doc/rdoc/classes/Mongrel/HttpHandler.html +159 -0
  13. data/doc/rdoc/classes/Mongrel/HttpHandler.src/M000019.html +17 -0
  14. data/doc/rdoc/classes/Mongrel/HttpParser.html +271 -0
  15. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000001.html +28 -0
  16. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000002.html +29 -0
  17. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000003.html +29 -0
  18. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000004.html +41 -0
  19. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000005.html +27 -0
  20. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000006.html +27 -0
  21. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000007.html +28 -0
  22. data/doc/rdoc/classes/Mongrel/HttpRequest.html +177 -0
  23. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000025.html +30 -0
  24. data/doc/rdoc/classes/Mongrel/HttpResponse.html +202 -0
  25. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000020.html +21 -0
  26. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000021.html +20 -0
  27. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000022.html +25 -0
  28. data/doc/rdoc/classes/Mongrel/HttpServer.html +336 -0
  29. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000008.html +26 -0
  30. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000009.html +58 -0
  31. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000010.html +22 -0
  32. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000011.html +18 -0
  33. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000012.html +18 -0
  34. data/doc/rdoc/classes/Mongrel/URIClassifier.html +257 -0
  35. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000015.html +54 -0
  36. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000016.html +50 -0
  37. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000017.html +36 -0
  38. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000018.html +73 -0
  39. data/doc/rdoc/created.rid +1 -0
  40. data/doc/rdoc/files/COPYING.html +756 -0
  41. data/doc/rdoc/files/LICENSE.html +756 -0
  42. data/doc/rdoc/files/README.html +273 -0
  43. data/doc/rdoc/files/ext/http11/http11_c.html +101 -0
  44. data/doc/rdoc/files/lib/mongrel_rb.html +111 -0
  45. data/doc/rdoc/fr_class_index.html +35 -0
  46. data/doc/rdoc/fr_file_index.html +31 -0
  47. data/doc/rdoc/fr_method_index.html +51 -0
  48. data/doc/rdoc/index.html +24 -0
  49. data/doc/rdoc/rdoc-style.css +208 -0
  50. data/examples/camping/blog.rb +300 -0
  51. data/examples/camping/tepee.rb +168 -0
  52. data/examples/simpletest.rb +16 -0
  53. data/examples/webrick_compare.rb +20 -0
  54. data/ext/http11/MANIFEST +0 -0
  55. data/ext/http11/ext_help.h +14 -0
  56. data/ext/http11/extconf.rb +6 -0
  57. data/ext/http11/http11.c +436 -0
  58. data/ext/http11/http11_parser.c +918 -0
  59. data/ext/http11/http11_parser.h +37 -0
  60. data/ext/http11/tst.h +40 -0
  61. data/ext/http11/tst_cleanup.c +24 -0
  62. data/ext/http11/tst_delete.c +146 -0
  63. data/ext/http11/tst_grow_node_free_list.c +38 -0
  64. data/ext/http11/tst_init.c +41 -0
  65. data/ext/http11/tst_insert.c +192 -0
  66. data/ext/http11/tst_search.c +54 -0
  67. data/lib/mongrel.rb +298 -0
  68. data/setup.rb +1360 -0
  69. data/test/test_http11.rb +38 -0
  70. data/test/test_response.rb +44 -0
  71. data/test/test_uriclassifier.rb +104 -0
  72. data/test/test_ws.rb +33 -0
  73. data/tools/rakehelp.rb +99 -0
  74. metadata +132 -0
data/README ADDED
@@ -0,0 +1,117 @@
1
+ = Mongrel: Simple Fast Mostly Ruby Web Server
2
+
3
+ Mongrel is a small library that provides a very fast HTTP 1.1 server for Ruby
4
+ web applications. It is not particular to any framework, and is intended to
5
+ be just enough to get a web application running behind a more complete and robust
6
+ web server.
7
+
8
+ What makes Mongrel so fast is the careful use of a C extension to provide fast
9
+ HTTP 1.1 protocol parsing and fast URI lookup. This combination makes the server
10
+ scream without too many portability issues.
11
+
12
+ == Status
13
+
14
+ The 0.2.0 release of Mongrel features an HTTP core server that is the fastest possible
15
+ thing I could get without using something other than Ruby. It features a few bug fixes,
16
+ but mostly just a change to the Mongrel::HttpResponse class to make it more feature
17
+ complete. The remaining development will be spent getting Mongrel to work with
18
+ other frameworks, adding additional needed features, and improving the concurrency
19
+ and speed.
20
+
21
+ The current release has samples from "why the lucky stiff" for his Camping
22
+ framework in the examples directory. Camping is a small micro framework
23
+ (http://rubyforge.org/projects/camping) which should work with Mongrel if
24
+ you use the subversion source for Camping.
25
+
26
+ This is also the first release onto the new Mongrel RubyForge project
27
+ page found at http://rubyforge.org/projects/mongrel/ thanks to Tom Copland.
28
+ I'll be looking to automate management of this, but feel free to use
29
+ rubyforge to post feature requests, bugs, and join the mailing list.
30
+
31
+
32
+ == Install
33
+
34
+ It doesn't explicitly require Camping, but if you want to run the examples/camping/
35
+ examples then you'll need to install Camping 1.2 at least (and redcloth I think).
36
+ These are all available from RubyGems.
37
+
38
+ The library consists of a C extension so you'll need a C compiler or at least a friend
39
+ who can build it for you.
40
+
41
+ Finally, the source includes a setup.rb for those who hate RubyGems.
42
+
43
+
44
+ == Usage
45
+
46
+ The examples/simpletest.rb file has the following code as the simplest
47
+ example:
48
+
49
+ require 'mongrel'
50
+
51
+ class SimpleHandler < Mongrel::HttpHandler
52
+ def process(request, response)
53
+ response.start(200) do |head,out|
54
+ head["Content-Type"] = "text/plain"
55
+ out.write("hello!\n")
56
+ end
57
+ end
58
+ end
59
+
60
+ h = Mongrel::HttpServer.new("0.0.0.0", "3000")
61
+ h.register("/test", SimpleHandler.new)
62
+ h.run.join
63
+
64
+ If you run this and access port 3000 with a browser it will say
65
+ "hello!". If you access it with any url other than "/test" it will
66
+ give a simple 404. Check out the Mongrel::Error404Handler for a
67
+ basic way to give a more complex 404 message.
68
+
69
+ == Speed
70
+
71
+ The 0.2.0 release probably consists of the most effort I've ever put into
72
+ tuning a Ruby library for speed. It consists of nearly everything I could think
73
+ of to make Mongrel the fastest Ruby HTTP library possible. I've tried about
74
+ seven different architectures and IO processing methods and none of them
75
+ make it any faster. In short: Mongrel is amazingly fast considering Ruby's speed
76
+ limitations.
77
+
78
+ This release also brings in controllable threads that you can scale to meet your
79
+ needs to do your processing. Simple pass in the HttpServer.new third optional
80
+ parameter:
81
+
82
+ h = Mongrel::HttpServer.new("0.0.0.0", "3000", 40)
83
+
84
+ Which will make 40 thread processors. Right now the optimal setting is up in
85
+ the air, but 20 seemed to be about the sweet spot on my systems. The
86
+ limited processors also means that you can use ActiveRecord as-is and it will
87
+ create a matching database connection for each processor thread. More on
88
+ this in future releases.
89
+
90
+ With this release I'm hoping that I've created a nice solid fast as hell core
91
+ upon which I can build the remaining features I want in Mongrel.
92
+
93
+ == The Future
94
+
95
+ With the core of Mongrel completed I'm now turning to the next set of features
96
+ to make Mongrel useful for hosting web applications in a heavily utilized
97
+ production environment. Right now I'm looking at:
98
+
99
+ * Fast static file handling with directory listings.
100
+ * More testing on more platforms.
101
+ * An idea I've had for an insane caching handler which could speed up quite a
102
+ few deployments.
103
+ * General little things most web servers need.
104
+ * A nice management system or interface for controlling mongrel servers.
105
+
106
+ Overall though the goal of Mongrel is to be just enough HTTP to serve a Ruby
107
+ web application that sits behind a more complete web server. Everything
108
+ in the next will focus on actually hosting the major web frameworks for Ruby:
109
+
110
+ * Camping -- because it's already done (thanks Why).
111
+ * Ruby on Rails -- that's where my bread is buttered right now.
112
+ * Nitro -- George is a nice guy, and Nitro is thread safe. Might be fun.
113
+ * ????? -- Others people might be interested in.
114
+
115
+ == Contact
116
+
117
+ E-mail zedshaw at zedshaw.com and I'll help. Comments about the API are welcome.
@@ -0,0 +1,30 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'tools/rakehelp'
7
+ require 'fileutils'
8
+ include FileUtils
9
+
10
+ setup_tests
11
+ setup_clean ["ext/http11/Makefile", "pkg", "lib/*.bundle", "ext/http11/*.bundle"]
12
+ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/*.rb',
13
+ 'doc/**/*.rdoc', 'ext/http11/http11.c']
14
+
15
+ desc "Does a full compile, test run"
16
+ task :default => [:compile, :test]
17
+
18
+ desc "Compiles all extensions"
19
+ task :compile => [:http11]
20
+ task :package => [:clean]
21
+
22
+ task :ragel do
23
+ sh %{/usr/local/bin/ragel ext/http11/http11_parser.rl | /usr/local/bin/rlcodegen -G2 -o ext/http11/http11_parser.c}
24
+ end
25
+
26
+ setup_extension("http11", "http11")
27
+
28
+ summary = "An experimental fast simple web server for Ruby."
29
+ test_file = "test/test_ws.rb"
30
+ setup_gem("mongrel", "0.2.0", "Zed A. Shaw", summary, [], test_file)
@@ -0,0 +1,144 @@
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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Mongrel</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Mongrel</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/mongrel_rb.html">
59
+ lib/mongrel.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/ext/http11/http11_c.html">
63
+ ext/http11/http11.c
64
+ </a>
65
+ <br />
66
+ </td>
67
+ </tr>
68
+
69
+ </table>
70
+ </div>
71
+ <!-- banner header -->
72
+
73
+ <div id="bodyContent">
74
+
75
+
76
+
77
+ <div id="contextContent">
78
+
79
+ <div id="description">
80
+ <p>
81
+ <a href="Mongrel.html">Mongrel</a> module containing all of the classes
82
+ (include C extensions) for running a <a href="Mongrel.html">Mongrel</a> web
83
+ server. It contains a minimalist HTTP server with just enough functionality
84
+ to service web application requests fast as possible.
85
+ </p>
86
+
87
+ </div>
88
+
89
+
90
+ </div>
91
+
92
+
93
+ </div>
94
+
95
+
96
+ <!-- if includes -->
97
+
98
+ <div id="section">
99
+
100
+ <div id="class-list">
101
+ <h3 class="section-bar">Classes and Modules</h3>
102
+
103
+ Class <a href="Mongrel/Error404Handler.html" class="link">Mongrel::Error404Handler</a><br />
104
+ Class <a href="Mongrel/HeaderOut.html" class="link">Mongrel::HeaderOut</a><br />
105
+ Class <a href="Mongrel/HttpHandler.html" class="link">Mongrel::HttpHandler</a><br />
106
+ Class <a href="Mongrel/HttpParser.html" class="link">Mongrel::HttpParser</a><br />
107
+ Class <a href="Mongrel/HttpRequest.html" class="link">Mongrel::HttpRequest</a><br />
108
+ Class <a href="Mongrel/HttpResponse.html" class="link">Mongrel::HttpResponse</a><br />
109
+ Class <a href="Mongrel/HttpServer.html" class="link">Mongrel::HttpServer</a><br />
110
+ Class <a href="Mongrel/URIClassifier.html" class="link">Mongrel::URIClassifier</a><br />
111
+
112
+ </div>
113
+
114
+ <div id="constants-list">
115
+ <h3 class="section-bar">Constants</h3>
116
+
117
+ <div class="name-list">
118
+ <table summary="Constants">
119
+ <tr class="top-aligned-row context-row">
120
+ <td class="context-item-name">HTTP_STATUS_CODES</td>
121
+ <td>=</td>
122
+ <td class="context-item-value">{ 100 =&gt; 'Continue', 101 =&gt; 'Switching Protocols', 200 =&gt; 'OK', 201 =&gt; 'Created', 202 =&gt; 'Accepted', 203 =&gt; 'Non-Authoritative Information', 204 =&gt; 'No Content', 205 =&gt; 'Reset Content', 206 =&gt; 'Partial Content', 300 =&gt; 'Multiple Choices', 301 =&gt; 'Moved Permanently', 302 =&gt; 'Moved Temporarily', 303 =&gt; 'See Other', 304 =&gt; 'Not Modified', 305 =&gt; 'Use Proxy', 400 =&gt; 'Bad Request', 401 =&gt; 'Unauthorized', 402 =&gt; 'Payment Required', 403 =&gt; 'Forbidden', 404 =&gt; 'Not Found', 405 =&gt; 'Method Not Allowed', 406 =&gt; 'Not Acceptable', 407 =&gt; 'Proxy Authentication Required', 408 =&gt; 'Request Time-out', 409 =&gt; 'Conflict', 410 =&gt; 'Gone', 411 =&gt; 'Length Required', 412 =&gt; 'Precondition Failed', 413 =&gt; 'Request Entity Too Large', 414 =&gt; 'Request-URI Too Large', 415 =&gt; 'Unsupported Media Type', 500 =&gt; 'Internal Server Error', 501 =&gt; 'Not Implemented', 502 =&gt; 'Bad Gateway', 503 =&gt; 'Service Unavailable', 504 =&gt; 'Gateway Time-out', 505 =&gt; 'HTTP Version not supported'</td>
123
+ </tr>
124
+ </table>
125
+ </div>
126
+ </div>
127
+
128
+
129
+
130
+
131
+
132
+
133
+ <!-- if method_list -->
134
+
135
+
136
+ </div>
137
+
138
+
139
+ <div id="validator-badges">
140
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
141
+ </div>
142
+
143
+ </body>
144
+ </html>
@@ -0,0 +1,171 @@
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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Mongrel::Error404Handler</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Mongrel::Error404Handler</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/mongrel_rb.html">
59
+ lib/mongrel.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ <a href="HttpHandler.html">
69
+ HttpHandler
70
+ </a>
71
+ </td>
72
+ </tr>
73
+ </table>
74
+ </div>
75
+ <!-- banner header -->
76
+
77
+ <div id="bodyContent">
78
+
79
+
80
+
81
+ <div id="contextContent">
82
+
83
+ <div id="description">
84
+ <p>
85
+ The server normally returns a 404 response if a URI is requested, but it
86
+ also returns a lame empty message. This lets you do a 404 response with a
87
+ custom message for special URIs.
88
+ </p>
89
+
90
+ </div>
91
+
92
+
93
+ </div>
94
+
95
+ <div id="method-list">
96
+ <h3 class="section-bar">Methods</h3>
97
+
98
+ <div class="name-list">
99
+ <a href="#M000023">new</a>&nbsp;&nbsp;
100
+ <a href="#M000024">process</a>&nbsp;&nbsp;
101
+ </div>
102
+ </div>
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+
109
+ <div id="section">
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ <!-- if method_list -->
119
+ <div id="methods">
120
+ <h3 class="section-bar">Public Class methods</h3>
121
+
122
+ <div id="method-M000023" class="method-detail">
123
+ <a name="M000023"></a>
124
+
125
+ <div class="method-heading">
126
+ <a href="Error404Handler.src/M000023.html" target="Code" class="method-signature"
127
+ onclick="popupCode('Error404Handler.src/M000023.html');return false;">
128
+ <span class="method-name">new</span><span class="method-args">(msg)</span>
129
+ </a>
130
+ </div>
131
+
132
+ <div class="method-description">
133
+ <p>
134
+ Sets the message to return. This is constructed once for the handler so
135
+ it&#8217;s pretty efficient.
136
+ </p>
137
+ </div>
138
+ </div>
139
+
140
+ <h3 class="section-bar">Public Instance methods</h3>
141
+
142
+ <div id="method-M000024" class="method-detail">
143
+ <a name="M000024"></a>
144
+
145
+ <div class="method-heading">
146
+ <a href="Error404Handler.src/M000024.html" target="Code" class="method-signature"
147
+ onclick="popupCode('Error404Handler.src/M000024.html');return false;">
148
+ <span class="method-name">process</span><span class="method-args">(request, response)</span>
149
+ </a>
150
+ </div>
151
+
152
+ <div class="method-description">
153
+ <p>
154
+ Just kicks back the standard 404 response with your special message.
155
+ </p>
156
+ </div>
157
+ </div>
158
+
159
+
160
+ </div>
161
+
162
+
163
+ </div>
164
+
165
+
166
+ <div id="validator-badges">
167
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
168
+ </div>
169
+
170
+ </body>
171
+ </html>