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
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require 'http11'
3
+
4
+
5
+ class HttpParserTest < Test::Unit::TestCase
6
+
7
+ def test_parse_simple
8
+ parser = HttpParser.new
9
+ req = {}
10
+ http = "GET / HTTP/1.1\r\n\r\n"
11
+ nread = parser.execute(req, http);
12
+ assert nread == http.length, "Failed to parse the full HTTP request"
13
+ assert parser.finished?, "Parser didn't finish"
14
+ assert !parser.error?, "Parser had error"
15
+ assert nread == parser.nread, "Number read returned from execute does not match"
16
+ parser.reset
17
+ assert parser.nread == 0, "Number read after reset should be 0"
18
+ end
19
+
20
+
21
+ def test_parse_error
22
+ parser = HttpParser.new
23
+ req = {}
24
+ bad_http = "GET / SsUTF/1.1"
25
+
26
+ error = false
27
+ begin
28
+ nread = parser.execute(req, bad_http)
29
+ rescue => details
30
+ error = true
31
+ end
32
+
33
+ assert error, "failed to throw exception"
34
+ assert !parser.finished?, "Parser shouldn't be finished"
35
+ assert parser.error?, "Parser SHOULD have error"
36
+ end
37
+ end
38
+
@@ -0,0 +1,44 @@
1
+ require 'test/unit'
2
+ require 'mongrel'
3
+
4
+ include Mongrel
5
+
6
+ class ResponseTest < Test::Unit::TestCase
7
+
8
+ def test_response_headers
9
+ out = StringIO.new
10
+ resp = HttpResponse.new(out)
11
+ resp.status = 200
12
+ resp.header["Accept"] = "text/plain"
13
+ resp.header["X-Whatever"] = "stuff"
14
+ resp.body.write("test")
15
+ resp.finished
16
+
17
+ assert out.length > 0, "output didn't have data"
18
+ end
19
+
20
+ def test_response_200
21
+ io = StringIO.new
22
+ resp = HttpResponse.new(io)
23
+ resp.start do |head,out|
24
+ head["Accept"] = "text/plain"
25
+ out.write("tested")
26
+ out.write("hello!")
27
+ end
28
+ assert io.length > 0, "output didn't have data"
29
+ end
30
+
31
+ def test_response_404
32
+ io = StringIO.new
33
+
34
+ resp = HttpResponse.new(io)
35
+ resp.start(404) do |head,out|
36
+ head['Accept'] = "text/plain"
37
+ out.write("NOT FOUND")
38
+ end
39
+
40
+ assert io.length > 0, "output didn't have data"
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,104 @@
1
+ require 'test/unit'
2
+ require 'net/http'
3
+ require 'mongrel'
4
+ require 'benchmark'
5
+
6
+ include Mongrel
7
+
8
+ class URIClassifierTest < Test::Unit::TestCase
9
+
10
+ def test_uri_finding
11
+ u = URIClassifier.new
12
+ u.register("/test", 1)
13
+
14
+ sn,pi,val = u.resolve("/test")
15
+ assert val != nil, "didn't resolve"
16
+ assert_equal 1, val, "wrong value"
17
+ assert_equal "/test",sn, "wrong SCRIPT_NAME"
18
+ end
19
+
20
+
21
+ def test_uri_prefix_ops
22
+ test = "/pre/fix/test"
23
+ prefix = "/pre"
24
+
25
+ u = URIClassifier.new
26
+ u.register(prefix,1)
27
+
28
+ sn,pi,val = u.resolve(test)
29
+ assert val != nil, "didn't resolve"
30
+ assert_equal prefix,sn, "wrong script name"
31
+ assert_equal test[sn.length .. -1],pi, "wrong path info"
32
+ end
33
+
34
+ def test_not_finding
35
+ test = "/cant/find/me"
36
+ u = URIClassifier.new
37
+ u.register(test, 1)
38
+
39
+ sn,pi,val = u.resolve("/nope/not/here")
40
+ assert_equal nil,sn, "shouldn't be found"
41
+ assert_equal nil,pi, "shouldn't be found"
42
+ assert_equal nil,val, "shouldn't be found"
43
+ end
44
+
45
+ def test_exceptions
46
+ u = URIClassifier.new
47
+
48
+ u.register("test", 1)
49
+
50
+ failed = false
51
+ begin
52
+ u.register("test", 1)
53
+ rescue => e
54
+ failed = true
55
+ end
56
+
57
+ assert failed, "it didn't fail as expected"
58
+
59
+ failed = false
60
+ begin
61
+ u.register("", 1)
62
+ rescue => e
63
+ failed = true
64
+ end
65
+
66
+ assert failed, "it didn't fail as expected"
67
+ end
68
+
69
+
70
+ def test_register_unregister
71
+ u = URIClassifier.new
72
+
73
+ 100.times do
74
+ u.register("stuff", 1)
75
+ val = u.unregister("stuff")
76
+ assert_equal 1,val, "didn't get the right return value"
77
+ end
78
+
79
+ u.register("things",1)
80
+ sn,pi,val = u.resolve("things")
81
+ assert_equal 1, val, "result doesn't match"
82
+
83
+ u.unregister("things")
84
+ sn,pi,val = u.resolve("things")
85
+ assert_equal nil, val, "result should be nil"
86
+
87
+ end
88
+
89
+
90
+ def test_performance
91
+ count = 8500
92
+ u = URIClassifier.new
93
+ u.register("stuff",1)
94
+
95
+ res = Benchmark.measure { count.times { u.resolve("stuff") } }
96
+
97
+ reg_unreg = Benchmark.measure { count.times { u.register("other",1); u.unregister("other"); } }
98
+
99
+ puts "\nRESOLVE(#{count}): #{res}"
100
+ puts "REG_UNREG(#{count}): #{reg_unreg}"
101
+ end
102
+
103
+ end
104
+
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+ require 'net/http'
3
+ require 'mongrel'
4
+ require 'timeout'
5
+
6
+ include Mongrel;
7
+
8
+ class TestHandler < Mongrel::HttpHandler
9
+ attr_reader :ran_test
10
+
11
+ def process(request, response)
12
+ @ran_test = true
13
+ response.socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nhello!\n")
14
+ end
15
+ end
16
+
17
+
18
+ class WSTest < Test::Unit::TestCase
19
+
20
+ def test_simple_server
21
+ h = HttpServer.new("0.0.0.0", 9998)
22
+ tester = TestHandler.new
23
+ h.register("/test", tester)
24
+ h.run
25
+
26
+ sleep(1)
27
+ res = Net::HTTP.get(URI.parse('http://localhost:9998/test'))
28
+ assert res != nil, "Didn't get a response"
29
+ assert tester.ran_test, "Handler didn't really run"
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,99 @@
1
+
2
+ def make(makedir)
3
+ Dir.chdir(makedir) do
4
+ sh 'make'
5
+ end
6
+ end
7
+
8
+
9
+ def extconf(dir)
10
+ Dir.chdir(dir) do ruby "extconf.rb" end
11
+ end
12
+
13
+
14
+ def setup_tests
15
+ Rake::TestTask.new do |t|
16
+ t.libs << "test"
17
+ t.test_files = FileList['test/test*.rb']
18
+ t.verbose = true
19
+ end
20
+ end
21
+
22
+
23
+ def setup_clean otherfiles
24
+ files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
25
+ CLEAN.include(files)
26
+ end
27
+
28
+
29
+ def setup_rdoc files
30
+ Rake::RDocTask.new do |rdoc|
31
+ rdoc.rdoc_dir = 'doc/rdoc'
32
+ rdoc.options << '--line-numbers'
33
+ rdoc.rdoc_files.add(files)
34
+ end
35
+ end
36
+
37
+
38
+ def setup_extension(dir, extension)
39
+ ext = "ext/#{dir}"
40
+ ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
41
+ ext_files = FileList[
42
+ "#{ext}/*.c",
43
+ "#{ext}/*.h",
44
+ "#{ext}/extconf.rb",
45
+ "#{ext}/Makefile",
46
+ "lib"
47
+ ]
48
+
49
+ task "lib" do
50
+ directory "lib"
51
+ end
52
+
53
+ desc "Builds just the #{extension} extension"
54
+ task extension.to_sym => ["#{ext}/Makefile", ext_so ]
55
+
56
+ file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
57
+ extconf "#{ext}"
58
+ end
59
+
60
+ file ext_so => ext_files do
61
+ make "#{ext}"
62
+ cp ext_so, "lib"
63
+ end
64
+ end
65
+
66
+
67
+ def setup_gem(pkg_name, pkg_version, author, summary, executables, test_file)
68
+ pkg_version = pkg_version
69
+ pkg_name = pkg_name
70
+ pkg_file_name = "#{pkg_name}-#{pkg_version}"
71
+
72
+ spec = Gem::Specification.new do |s|
73
+ s.name = pkg_name
74
+ s.version = pkg_version
75
+ s.platform = Gem::Platform::RUBY
76
+ s.author = author
77
+ s.summary = summary
78
+ s.test_file = test_file
79
+ s.has_rdoc = true
80
+ s.extra_rdoc_files = [ "README" ]
81
+
82
+ s.files = %w(COPYING LICENSE ext/http11/MANIFEST README Rakefile setup.rb) +
83
+ Dir.glob("{bin,doc,test,lib}/**/*") +
84
+ Dir.glob("ext/**/*.{h,c,rb}") +
85
+ Dir.glob("examples/**/*.rb") +
86
+ Dir.glob("tools/*.rb")
87
+
88
+ s.require_path = "lib"
89
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
90
+
91
+ s.executables = executables
92
+ s.bindir = "bin"
93
+ end
94
+
95
+ Rake::GemPackageTask.new(spec) do |p|
96
+ p.gem_spec = spec
97
+ p.need_tar = true
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: mongrel
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.2.0
7
+ date: 2006-01-31 00:00:00 -05:00
8
+ summary: An experimental fast simple web server for Ruby.
9
+ require_paths:
10
+ - lib
11
+ email:
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Zed A. Shaw
30
+ files:
31
+ - COPYING
32
+ - LICENSE
33
+ - ext/http11/MANIFEST
34
+ - README
35
+ - Rakefile
36
+ - setup.rb
37
+ - doc/rdoc
38
+ - doc/rdoc/classes
39
+ - doc/rdoc/created.rid
40
+ - doc/rdoc/files
41
+ - doc/rdoc/fr_class_index.html
42
+ - doc/rdoc/fr_file_index.html
43
+ - doc/rdoc/fr_method_index.html
44
+ - doc/rdoc/index.html
45
+ - doc/rdoc/rdoc-style.css
46
+ - doc/rdoc/classes/Mongrel
47
+ - doc/rdoc/classes/Mongrel.html
48
+ - doc/rdoc/classes/Mongrel/Error404Handler.html
49
+ - doc/rdoc/classes/Mongrel/Error404Handler.src
50
+ - doc/rdoc/classes/Mongrel/HeaderOut.html
51
+ - doc/rdoc/classes/Mongrel/HeaderOut.src
52
+ - doc/rdoc/classes/Mongrel/HttpHandler.html
53
+ - doc/rdoc/classes/Mongrel/HttpHandler.src
54
+ - doc/rdoc/classes/Mongrel/HttpParser.html
55
+ - doc/rdoc/classes/Mongrel/HttpParser.src
56
+ - doc/rdoc/classes/Mongrel/HttpRequest.html
57
+ - doc/rdoc/classes/Mongrel/HttpRequest.src
58
+ - doc/rdoc/classes/Mongrel/HttpResponse.html
59
+ - doc/rdoc/classes/Mongrel/HttpResponse.src
60
+ - doc/rdoc/classes/Mongrel/HttpServer.html
61
+ - doc/rdoc/classes/Mongrel/HttpServer.src
62
+ - doc/rdoc/classes/Mongrel/URIClassifier.html
63
+ - doc/rdoc/classes/Mongrel/URIClassifier.src
64
+ - doc/rdoc/classes/Mongrel/Error404Handler.src/M000023.html
65
+ - doc/rdoc/classes/Mongrel/Error404Handler.src/M000024.html
66
+ - doc/rdoc/classes/Mongrel/HeaderOut.src/M000013.html
67
+ - doc/rdoc/classes/Mongrel/HeaderOut.src/M000014.html
68
+ - doc/rdoc/classes/Mongrel/HttpHandler.src/M000019.html
69
+ - doc/rdoc/classes/Mongrel/HttpParser.src/M000001.html
70
+ - doc/rdoc/classes/Mongrel/HttpParser.src/M000002.html
71
+ - doc/rdoc/classes/Mongrel/HttpParser.src/M000003.html
72
+ - doc/rdoc/classes/Mongrel/HttpParser.src/M000004.html
73
+ - doc/rdoc/classes/Mongrel/HttpParser.src/M000005.html
74
+ - doc/rdoc/classes/Mongrel/HttpParser.src/M000006.html
75
+ - doc/rdoc/classes/Mongrel/HttpParser.src/M000007.html
76
+ - doc/rdoc/classes/Mongrel/HttpRequest.src/M000025.html
77
+ - doc/rdoc/classes/Mongrel/HttpResponse.src/M000020.html
78
+ - doc/rdoc/classes/Mongrel/HttpResponse.src/M000021.html
79
+ - doc/rdoc/classes/Mongrel/HttpResponse.src/M000022.html
80
+ - doc/rdoc/classes/Mongrel/HttpServer.src/M000008.html
81
+ - doc/rdoc/classes/Mongrel/HttpServer.src/M000009.html
82
+ - doc/rdoc/classes/Mongrel/HttpServer.src/M000010.html
83
+ - doc/rdoc/classes/Mongrel/HttpServer.src/M000011.html
84
+ - doc/rdoc/classes/Mongrel/HttpServer.src/M000012.html
85
+ - doc/rdoc/classes/Mongrel/URIClassifier.src/M000015.html
86
+ - doc/rdoc/classes/Mongrel/URIClassifier.src/M000016.html
87
+ - doc/rdoc/classes/Mongrel/URIClassifier.src/M000017.html
88
+ - doc/rdoc/classes/Mongrel/URIClassifier.src/M000018.html
89
+ - doc/rdoc/files/COPYING.html
90
+ - doc/rdoc/files/ext
91
+ - doc/rdoc/files/lib
92
+ - doc/rdoc/files/LICENSE.html
93
+ - doc/rdoc/files/README.html
94
+ - doc/rdoc/files/ext/http11
95
+ - doc/rdoc/files/ext/http11/http11_c.html
96
+ - doc/rdoc/files/lib/mongrel_rb.html
97
+ - test/test_http11.rb
98
+ - test/test_response.rb
99
+ - test/test_uriclassifier.rb
100
+ - test/test_ws.rb
101
+ - lib/mongrel.rb
102
+ - ext/http11/ext_help.h
103
+ - ext/http11/http11_parser.h
104
+ - ext/http11/tst.h
105
+ - ext/http11/http11.c
106
+ - ext/http11/http11_parser.c
107
+ - ext/http11/tst_cleanup.c
108
+ - ext/http11/tst_delete.c
109
+ - ext/http11/tst_grow_node_free_list.c
110
+ - ext/http11/tst_init.c
111
+ - ext/http11/tst_insert.c
112
+ - ext/http11/tst_search.c
113
+ - ext/http11/extconf.rb
114
+ - examples/simpletest.rb
115
+ - examples/webrick_compare.rb
116
+ - examples/camping/blog.rb
117
+ - examples/camping/tepee.rb
118
+ - tools/rakehelp.rb
119
+ test_files:
120
+ - test/test_ws.rb
121
+ rdoc_options: []
122
+
123
+ extra_rdoc_files:
124
+ - README
125
+ executables: []
126
+
127
+ extensions:
128
+ - ext/http11/extconf.rb
129
+ requirements: []
130
+
131
+ dependencies: []
132
+