thin 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of thin might be problematic. Click here for more details.

Files changed (91) hide show
  1. data/COPYING +18 -0
  2. data/README +32 -45
  3. data/Rakefile +66 -23
  4. data/bin/thin +76 -45
  5. data/doc/benchmarks.txt +64 -249
  6. data/doc/rdoc/created.rid +1 -1
  7. data/doc/rdoc/files/README.html +37 -100
  8. data/doc/rdoc/rdoc-style.css +5 -0
  9. data/example/config.ru +9 -0
  10. data/ext/thin_parser/common.rl +54 -0
  11. data/ext/thin_parser/ext_help.h +14 -0
  12. data/ext/thin_parser/extconf.rb +6 -0
  13. data/ext/thin_parser/parser.c +1199 -0
  14. data/ext/thin_parser/parser.h +49 -0
  15. data/ext/thin_parser/parser.rl +143 -0
  16. data/ext/thin_parser/thin.c +424 -0
  17. data/lib/rack/adapter/rails.rb +136 -0
  18. data/lib/rack/handler/thin.rb +13 -0
  19. data/lib/thin.rb +28 -12
  20. data/lib/thin/connection.rb +47 -0
  21. data/lib/thin/daemonizing.rb +5 -1
  22. data/lib/thin/headers.rb +3 -2
  23. data/lib/thin/logging.rb +6 -13
  24. data/lib/thin/request.rb +53 -133
  25. data/lib/thin/response.rb +21 -25
  26. data/lib/thin/server.rb +30 -94
  27. data/lib/thin/version.rb +2 -2
  28. data/lib/thin_parser.bundle +0 -0
  29. data/spec/daemonizing_spec.rb +94 -0
  30. data/spec/headers_spec.rb +35 -0
  31. data/spec/request_spec.rb +258 -0
  32. data/spec/response_spec.rb +40 -0
  33. data/spec/server_spec.rb +75 -0
  34. data/spec/spec_helper.rb +126 -0
  35. metadata +79 -99
  36. data/bin/thin_cluster +0 -53
  37. data/doc/rdoc/classes/Kernel.html +0 -182
  38. data/doc/rdoc/classes/Process.html +0 -175
  39. data/doc/rdoc/classes/Thin.html +0 -184
  40. data/doc/rdoc/classes/Thin/CGIWrapper.html +0 -438
  41. data/doc/rdoc/classes/Thin/Cluster.html +0 -392
  42. data/doc/rdoc/classes/Thin/Command.html +0 -221
  43. data/doc/rdoc/classes/Thin/CommandError.html +0 -154
  44. data/doc/rdoc/classes/Thin/Commands.html +0 -145
  45. data/doc/rdoc/classes/Thin/Daemonizable.html +0 -250
  46. data/doc/rdoc/classes/Thin/Daemonizable/ClassMethods.html +0 -203
  47. data/doc/rdoc/classes/Thin/DirHandler.html +0 -250
  48. data/doc/rdoc/classes/Thin/Handler.html +0 -195
  49. data/doc/rdoc/classes/Thin/Headers.html +0 -244
  50. data/doc/rdoc/classes/Thin/InvalidRequest.html +0 -150
  51. data/doc/rdoc/classes/Thin/Logging.html +0 -214
  52. data/doc/rdoc/classes/Thin/RailsHandler.html +0 -234
  53. data/doc/rdoc/classes/Thin/RailsServer.html +0 -175
  54. data/doc/rdoc/classes/Thin/Request.html +0 -379
  55. data/doc/rdoc/classes/Thin/Response.html +0 -311
  56. data/doc/rdoc/classes/Thin/Server.html +0 -381
  57. data/doc/rdoc/files/bin/thin.html +0 -188
  58. data/doc/rdoc/files/bin/thin_cluster.html +0 -175
  59. data/doc/rdoc/files/lib/thin/cgi_rb.html +0 -263
  60. data/doc/rdoc/files/lib/thin/cluster_rb.html +0 -263
  61. data/doc/rdoc/files/lib/thin/command_rb.html +0 -263
  62. data/doc/rdoc/files/lib/thin/consts_rb.html +0 -263
  63. data/doc/rdoc/files/lib/thin/daemonizing_rb.html +0 -263
  64. data/doc/rdoc/files/lib/thin/handler_rb.html +0 -263
  65. data/doc/rdoc/files/lib/thin/headers_rb.html +0 -263
  66. data/doc/rdoc/files/lib/thin/logging_rb.html +0 -263
  67. data/doc/rdoc/files/lib/thin/mime_types_rb.html +0 -263
  68. data/doc/rdoc/files/lib/thin/rails_rb.html +0 -263
  69. data/doc/rdoc/files/lib/thin/recipes_rb.html +0 -171
  70. data/doc/rdoc/files/lib/thin/request_rb.html +0 -171
  71. data/doc/rdoc/files/lib/thin/response_rb.html +0 -171
  72. data/doc/rdoc/files/lib/thin/server_rb.html +0 -171
  73. data/doc/rdoc/files/lib/thin/statuses_rb.html +0 -171
  74. data/doc/rdoc/files/lib/thin/version_rb.html +0 -171
  75. data/lib/thin/cgi.rb +0 -159
  76. data/lib/thin/cluster.rb +0 -147
  77. data/lib/thin/command.rb +0 -49
  78. data/lib/thin/commands/cluster/base.rb +0 -24
  79. data/lib/thin/commands/cluster/config.rb +0 -36
  80. data/lib/thin/commands/cluster/restart.rb +0 -35
  81. data/lib/thin/commands/cluster/start.rb +0 -40
  82. data/lib/thin/commands/cluster/stop.rb +0 -28
  83. data/lib/thin/commands/server/base.rb +0 -7
  84. data/lib/thin/commands/server/start.rb +0 -33
  85. data/lib/thin/commands/server/stop.rb +0 -29
  86. data/lib/thin/consts.rb +0 -37
  87. data/lib/thin/handler.rb +0 -57
  88. data/lib/thin/mime_types.rb +0 -619
  89. data/lib/thin/rails.rb +0 -44
  90. data/lib/thin/recipes.rb +0 -36
  91. data/lib/transat/parser.rb +0 -247
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Response do
4
+ before do
5
+ @response = Response.new
6
+ @response.headers['Content-Type'] = 'text/html'
7
+ end
8
+
9
+ it 'should output headers' do
10
+ @response.headers_output.should == "Content-Type: text/html\r\nContent-Length: 0\r\nConnection: close\r\n"
11
+ end
12
+
13
+ it 'should output head' do
14
+ @response.head.should == "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
15
+ end
16
+
17
+ it 'should allow duplicates in headers' do
18
+ @response.headers['Set-Cookie'] = 'mium=7'
19
+ @response.headers['Set-Cookie'] = 'hi=there'
20
+
21
+ @response.head.should == "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nSet-Cookie: mium=7\r\nSet-Cookie: hi=there\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
22
+ end
23
+
24
+ it 'should output body' do
25
+ @response.body << '<html></html>'
26
+
27
+ @response.to_s.should == "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 13\r\nConnection: close\r\n\r\n<html></html>"
28
+ end
29
+
30
+ it "should be faster then #{max_parsing_time = 0.06} ms" do
31
+ @response.body << <<-EOS
32
+ <html><head><title>Dir listing</title></head>
33
+ <body><h1>Listing stuff</h1><ul>
34
+ #{'<li>Hi!</li>' * 100}
35
+ </ul></body></html>
36
+ EOS
37
+
38
+ proc { @response.to_s }.should be_faster_then(max_parsing_time)
39
+ end
40
+ end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'net/http'
3
+ require 'socket'
4
+
5
+ describe Server do
6
+ before do
7
+ app = proc do |env|
8
+ body = [env['QUERY_STRING'], env['rack.input'].read].compact
9
+ [200, { 'Content-Type' => 'text/html' }, body]
10
+ end
11
+ server = Thin::Server.new('0.0.0.0', 3333, app)
12
+ server.timeout = 3
13
+ server.silent = true
14
+
15
+ server.start
16
+ @thread = Thread.new do
17
+ server.listen!
18
+ end
19
+ sleep 0.1 until @thread.status == 'sleep'
20
+ end
21
+
22
+ it 'should GET from Net::HTTP' do
23
+ get('/?cthis').should == 'cthis'
24
+ end
25
+
26
+ it 'should GET from TCPSocket' do
27
+ raw('0.0.0.0', 3333, "GET /?this HTTP/1.1\r\n\r\n").should == "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 4\r\nConnection: close\r\n\r\nthis"
28
+ end
29
+
30
+ it 'should return empty string on incomplete headers' do
31
+ raw('0.0.0.0', 3333, "GET /?this HTTP/1.1\r\nHost:").should be_empty
32
+ end
33
+
34
+ it 'should return empty string on incorrect Content-Length' do
35
+ raw('0.0.0.0', 3333, "POST / HTTP/1.1\r\nContent-Length: 300\r\n\r\naye").should be_empty
36
+ end
37
+
38
+ it 'should POST from Net::HTTP' do
39
+ post('/', :arg => 'pirate').should == 'arg=pirate'
40
+ end
41
+
42
+ it 'should handle big POST' do
43
+ big = 'X' * (20 * 1024)
44
+ post('/', :big => big).size.should == big.size + 4
45
+ end
46
+
47
+ it "should handle GET in less then #{get_request_time = 5} ms" do
48
+ proc { get('/') }.should be_faster_then(get_request_time)
49
+ end
50
+
51
+ it "should handle POST in less then #{post_request_time = 6} ms" do
52
+ proc { post('/', :file => 'X' * 1000) }.should be_faster_then(get_request_time)
53
+ end
54
+
55
+ after do
56
+ @thread.kill
57
+ end
58
+
59
+ private
60
+ def get(url)
61
+ Net::HTTP.get(URI.parse('http://0.0.0.0:3333' + url))
62
+ end
63
+
64
+ def raw(host, port, data)
65
+ socket = TCPSocket.new(host, port)
66
+ socket.write data
67
+ out = socket.read
68
+ socket.close
69
+ out
70
+ end
71
+
72
+ def post(url, params={})
73
+ Net::HTTP.post_form(URI.parse('http://0.0.0.0:3333' + url), params).body
74
+ end
75
+ end
@@ -0,0 +1,126 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/thin'
3
+ require 'spec'
4
+ require 'benchmark'
5
+ require 'timeout'
6
+
7
+ include Thin
8
+
9
+ FileUtils.mkdir_p File.dirname(__FILE__) + '/../log'
10
+
11
+ class TestRequest < Thin::Request
12
+ def initialize(path, verb='GET', params={})
13
+ @path = path
14
+ @verb = verb.to_s.upcase
15
+ @params = {
16
+ 'HTTP_HOST' => 'localhost:3000',
17
+ 'REQUEST_URI' => @path,
18
+ 'REQUEST_PATH' => @path,
19
+ 'REQUEST_METHOD' => @verb,
20
+ 'SCRIPT_NAME' => @path
21
+ }.merge(params)
22
+
23
+ @body = "#{@verb} #{path} HTTP/1.1"
24
+ end
25
+ end
26
+
27
+ module Matchers
28
+ class BeFasterThen
29
+ def initialize(max_time)
30
+ @max_time = max_time
31
+ end
32
+
33
+ def matches?(target)
34
+ @target = target
35
+ @time = Benchmark.measure { @target.call }.real * 1000
36
+ @time <= @max_time
37
+ end
38
+
39
+ def failure_message(less_more=:less)
40
+ "took #{@time} ms, should take #{less_more} then #{@max_time} ms"
41
+ end
42
+
43
+ def negative_failure_message
44
+ failure_message :more
45
+ end
46
+ end
47
+
48
+ class ValidateWithLint
49
+ def matches?(request)
50
+ @request = request
51
+ Rack::Lint.new(proc{[200, {'Content-Type' => 'text/html'}, []]}).call(@request.env)
52
+ true
53
+ rescue Rack::Lint::LintError => e
54
+ @message = e.message
55
+ false
56
+ end
57
+
58
+ def failure_message(negation=nil)
59
+ "should#{negation} validate with Rack Lint"
60
+ end
61
+
62
+ def negative_failure_message
63
+ failure_message ' not'
64
+ end
65
+ end
66
+
67
+ class TakeLessThen
68
+ def initialize(time)
69
+ @time = time
70
+ end
71
+
72
+ def matches?(proc)
73
+ Timeout.timeout(@time) { proc.call }
74
+ true
75
+ rescue Timeout::Error
76
+ false
77
+ end
78
+
79
+ def failure_message(negation=nil)
80
+ "should#{negation} take less then #{@time} sec to run"
81
+ end
82
+
83
+ def negative_failure_message
84
+ failure_message ' not'
85
+ end
86
+ end
87
+
88
+ # Actual matchers that are exposed.
89
+
90
+ def be_faster_then(time)
91
+ BeFasterThen.new(time)
92
+ end
93
+
94
+ def validate_with_lint
95
+ ValidateWithLint.new
96
+ end
97
+
98
+ def take_less_then(time)
99
+ TakeLessThen.new(time)
100
+ end
101
+ end
102
+
103
+ module Helpers
104
+ # Silences any stream for the duration of the block.
105
+ #
106
+ # silence_stream(STDOUT) do
107
+ # puts 'This will never be seen'
108
+ # end
109
+ #
110
+ # puts 'But this will'
111
+ #
112
+ # (Taken from ActiveSupport)
113
+ def silence_stream(stream)
114
+ old_stream = stream.dup
115
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
116
+ stream.sync = true
117
+ yield
118
+ ensure
119
+ stream.reopen(old_stream)
120
+ end
121
+ end
122
+
123
+ Spec::Runner.configure do |config|
124
+ config.include Matchers
125
+ config.include Helpers
126
+ end
metadata CHANGED
@@ -1,133 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: thin
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.1
7
- date: 2007-12-04 00:00:00 -05:00
8
- summary: Thin and fast web server
9
- require_paths:
10
- - lib
11
- email: macournoyer@gmail.com
12
- homepage: http://code.macournoyer.com/thin/
13
- rubyforge_project:
14
- description: Thin and fast web server
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.6
24
- version:
4
+ version: 0.5.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Marc-Andre Cournoyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-01 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: eventmachine
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.0
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rack
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.2.0
32
+ version:
33
+ description: A thin and fast web server
34
+ email: macournoyer@gmail.com
35
+ executables:
36
+ - thin
37
+ extensions:
38
+ - ext/thin_parser/extconf.rb
39
+ extra_rdoc_files: []
40
+
31
41
  files:
42
+ - COPYING
32
43
  - README
33
44
  - Rakefile
34
45
  - bin/thin
35
- - bin/thin_cluster
36
46
  - doc/benchmarks.txt
37
47
  - doc/rdoc
38
48
  - doc/rdoc/classes
39
- - doc/rdoc/classes/Kernel.html
40
- - doc/rdoc/classes/Process.html
41
- - doc/rdoc/classes/Thin
42
- - doc/rdoc/classes/Thin/CGIWrapper.html
43
- - doc/rdoc/classes/Thin/Cluster.html
44
- - doc/rdoc/classes/Thin/Command.html
45
- - doc/rdoc/classes/Thin/CommandError.html
46
- - doc/rdoc/classes/Thin/Commands.html
47
- - doc/rdoc/classes/Thin/Daemonizable
48
- - doc/rdoc/classes/Thin/Daemonizable/ClassMethods.html
49
- - doc/rdoc/classes/Thin/Daemonizable.html
50
- - doc/rdoc/classes/Thin/DirHandler.html
51
- - doc/rdoc/classes/Thin/Handler.html
52
- - doc/rdoc/classes/Thin/Headers.html
53
- - doc/rdoc/classes/Thin/InvalidRequest.html
54
- - doc/rdoc/classes/Thin/Logging.html
55
- - doc/rdoc/classes/Thin/RailsHandler.html
56
- - doc/rdoc/classes/Thin/RailsServer.html
57
- - doc/rdoc/classes/Thin/Request.html
58
- - doc/rdoc/classes/Thin/Response.html
59
- - doc/rdoc/classes/Thin/Server.html
60
- - doc/rdoc/classes/Thin.html
61
49
  - doc/rdoc/created.rid
62
50
  - doc/rdoc/files
63
- - doc/rdoc/files/bin
64
- - doc/rdoc/files/bin/thin.html
65
- - doc/rdoc/files/bin/thin_cluster.html
66
- - doc/rdoc/files/lib
67
- - doc/rdoc/files/lib/thin
68
- - doc/rdoc/files/lib/thin/cgi_rb.html
69
- - doc/rdoc/files/lib/thin/cluster_rb.html
70
- - doc/rdoc/files/lib/thin/command_rb.html
71
- - doc/rdoc/files/lib/thin/consts_rb.html
72
- - doc/rdoc/files/lib/thin/daemonizing_rb.html
73
- - doc/rdoc/files/lib/thin/handler_rb.html
74
- - doc/rdoc/files/lib/thin/headers_rb.html
75
- - doc/rdoc/files/lib/thin/logging_rb.html
76
- - doc/rdoc/files/lib/thin/mime_types_rb.html
77
- - doc/rdoc/files/lib/thin/rails_rb.html
78
- - doc/rdoc/files/lib/thin/recipes_rb.html
79
- - doc/rdoc/files/lib/thin/request_rb.html
80
- - doc/rdoc/files/lib/thin/response_rb.html
81
- - doc/rdoc/files/lib/thin/server_rb.html
82
- - doc/rdoc/files/lib/thin/statuses_rb.html
83
- - doc/rdoc/files/lib/thin/version_rb.html
84
51
  - doc/rdoc/files/README.html
85
52
  - doc/rdoc/index.html
86
53
  - doc/rdoc/logo.gif
87
54
  - doc/rdoc/rdoc-style.css
55
+ - spec/daemonizing_spec.rb
56
+ - spec/headers_spec.rb
57
+ - spec/request_spec.rb
58
+ - spec/response_spec.rb
59
+ - spec/server_spec.rb
60
+ - spec/spec_helper.rb
61
+ - lib/rack
62
+ - lib/rack/adapter
63
+ - lib/rack/adapter/rails.rb
64
+ - lib/rack/handler
65
+ - lib/rack/handler/thin.rb
88
66
  - lib/thin
89
- - lib/thin/cgi.rb
90
- - lib/thin/cluster.rb
91
- - lib/thin/command.rb
92
- - lib/thin/commands
93
- - lib/thin/commands/cluster
94
- - lib/thin/commands/cluster/base.rb
95
- - lib/thin/commands/cluster/config.rb
96
- - lib/thin/commands/cluster/restart.rb
97
- - lib/thin/commands/cluster/start.rb
98
- - lib/thin/commands/cluster/stop.rb
99
- - lib/thin/commands/server
100
- - lib/thin/commands/server/base.rb
101
- - lib/thin/commands/server/start.rb
102
- - lib/thin/commands/server/stop.rb
103
- - lib/thin/consts.rb
67
+ - lib/thin/connection.rb
104
68
  - lib/thin/daemonizing.rb
105
- - lib/thin/handler.rb
106
69
  - lib/thin/headers.rb
107
70
  - lib/thin/logging.rb
108
- - lib/thin/mime_types.rb
109
- - lib/thin/rails.rb
110
- - lib/thin/recipes.rb
111
71
  - lib/thin/request.rb
112
72
  - lib/thin/response.rb
113
73
  - lib/thin/server.rb
114
74
  - lib/thin/statuses.rb
115
75
  - lib/thin/version.rb
116
76
  - lib/thin.rb
117
- - lib/transat
118
- - lib/transat/parser.rb
119
- test_files: []
120
-
77
+ - lib/thin_parser.bundle
78
+ - example/config.ru
79
+ - ext/thin_parser/ext_help.h
80
+ - ext/thin_parser/parser.h
81
+ - ext/thin_parser/parser.c
82
+ - ext/thin_parser/thin.c
83
+ - ext/thin_parser/extconf.rb
84
+ - ext/thin_parser/common.rl
85
+ - ext/thin_parser/parser.rl
86
+ has_rdoc: false
87
+ homepage: http://code.macournoyer.com/thin/
88
+ post_install_message:
121
89
  rdoc_options: []
122
90
 
123
- extra_rdoc_files: []
124
-
125
- executables:
126
- - thin
127
- - thin_cluster
128
- extensions: []
129
-
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 1.8.6
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
130
105
  requirements: []
131
106
 
132
- dependencies: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.0.1
109
+ signing_key:
110
+ specification_version: 2
111
+ summary: A thin and fast web server
112
+ test_files: []
133
113