rack 1.6.11 → 2.2.0

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

Potentially problematic release.


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

Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +675 -0
  3. data/CONTRIBUTING.md +136 -0
  4. data/{COPYING → MIT-LICENSE} +4 -2
  5. data/README.rdoc +157 -163
  6. data/Rakefile +38 -32
  7. data/{SPEC → SPEC.rdoc} +41 -13
  8. data/bin/rackup +1 -0
  9. data/contrib/rack_logo.svg +164 -111
  10. data/example/lobster.ru +2 -0
  11. data/example/protectedlobster.rb +4 -2
  12. data/example/protectedlobster.ru +3 -1
  13. data/lib/rack/auth/abstract/handler.rb +3 -1
  14. data/lib/rack/auth/abstract/request.rb +6 -2
  15. data/lib/rack/auth/basic.rb +7 -4
  16. data/lib/rack/auth/digest/md5.rb +13 -11
  17. data/lib/rack/auth/digest/nonce.rb +6 -3
  18. data/lib/rack/auth/digest/params.rb +5 -4
  19. data/lib/rack/auth/digest/request.rb +6 -4
  20. data/lib/rack/body_proxy.rb +21 -15
  21. data/lib/rack/builder.rb +119 -26
  22. data/lib/rack/cascade.rb +28 -12
  23. data/lib/rack/chunked.rb +70 -22
  24. data/lib/rack/common_logger.rb +80 -0
  25. data/lib/rack/{conditionalget.rb → conditional_get.rb} +20 -16
  26. data/lib/rack/config.rb +2 -0
  27. data/lib/rack/content_length.rb +9 -8
  28. data/lib/rack/content_type.rb +5 -4
  29. data/lib/rack/core_ext/regexp.rb +14 -0
  30. data/lib/rack/deflater.rb +60 -70
  31. data/lib/rack/directory.rb +117 -85
  32. data/lib/rack/etag.rb +9 -7
  33. data/lib/rack/events.rb +153 -0
  34. data/lib/rack/file.rb +4 -149
  35. data/lib/rack/files.rb +218 -0
  36. data/lib/rack/handler/cgi.rb +17 -19
  37. data/lib/rack/handler/fastcgi.rb +17 -18
  38. data/lib/rack/handler/lsws.rb +14 -14
  39. data/lib/rack/handler/scgi.rb +22 -21
  40. data/lib/rack/handler/thin.rb +20 -11
  41. data/lib/rack/handler/webrick.rb +39 -32
  42. data/lib/rack/handler.rb +9 -26
  43. data/lib/rack/head.rb +16 -18
  44. data/lib/rack/lint.rb +110 -64
  45. data/lib/rack/lobster.rb +10 -10
  46. data/lib/rack/lock.rb +17 -11
  47. data/lib/rack/logger.rb +4 -2
  48. data/lib/rack/media_type.rb +43 -0
  49. data/lib/rack/{methodoverride.rb → method_override.rb} +10 -8
  50. data/lib/rack/mime.rb +27 -6
  51. data/lib/rack/mock.rb +124 -65
  52. data/lib/rack/multipart/generator.rb +20 -16
  53. data/lib/rack/multipart/parser.rb +273 -162
  54. data/lib/rack/multipart/uploaded_file.rb +15 -8
  55. data/lib/rack/multipart.rb +39 -8
  56. data/lib/rack/{nulllogger.rb → null_logger.rb} +3 -1
  57. data/lib/rack/query_parser.rb +217 -0
  58. data/lib/rack/recursive.rb +11 -9
  59. data/lib/rack/reloader.rb +8 -4
  60. data/lib/rack/request.rb +543 -305
  61. data/lib/rack/response.rb +244 -88
  62. data/lib/rack/rewindable_input.rb +5 -15
  63. data/lib/rack/runtime.rb +12 -18
  64. data/lib/rack/sendfile.rb +17 -15
  65. data/lib/rack/server.rb +125 -47
  66. data/lib/rack/session/abstract/id.rb +216 -93
  67. data/lib/rack/session/cookie.rb +47 -31
  68. data/lib/rack/session/memcache.rb +4 -87
  69. data/lib/rack/session/pool.rb +26 -17
  70. data/lib/rack/show_exceptions.rb +390 -0
  71. data/lib/rack/{showstatus.rb → show_status.rb} +8 -8
  72. data/lib/rack/static.rb +48 -11
  73. data/lib/rack/tempfile_reaper.rb +3 -3
  74. data/lib/rack/urlmap.rb +26 -19
  75. data/lib/rack/utils.rb +208 -294
  76. data/lib/rack/version.rb +29 -0
  77. data/lib/rack.rb +76 -33
  78. data/rack.gemspec +43 -30
  79. metadata +62 -183
  80. data/HISTORY.md +0 -375
  81. data/KNOWN-ISSUES +0 -44
  82. data/lib/rack/backports/uri/common_18.rb +0 -56
  83. data/lib/rack/backports/uri/common_192.rb +0 -52
  84. data/lib/rack/backports/uri/common_193.rb +0 -29
  85. data/lib/rack/commonlogger.rb +0 -72
  86. data/lib/rack/handler/evented_mongrel.rb +0 -8
  87. data/lib/rack/handler/mongrel.rb +0 -106
  88. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  89. data/lib/rack/showexceptions.rb +0 -387
  90. data/lib/rack/utils/okjson.rb +0 -600
  91. data/test/builder/anything.rb +0 -5
  92. data/test/builder/comment.ru +0 -4
  93. data/test/builder/end.ru +0 -5
  94. data/test/builder/line.ru +0 -1
  95. data/test/builder/options.ru +0 -2
  96. data/test/cgi/assets/folder/test.js +0 -1
  97. data/test/cgi/assets/fonts/font.eot +0 -1
  98. data/test/cgi/assets/images/image.png +0 -1
  99. data/test/cgi/assets/index.html +0 -1
  100. data/test/cgi/assets/javascripts/app.js +0 -1
  101. data/test/cgi/assets/stylesheets/app.css +0 -1
  102. data/test/cgi/lighttpd.conf +0 -26
  103. data/test/cgi/rackup_stub.rb +0 -6
  104. data/test/cgi/sample_rackup.ru +0 -5
  105. data/test/cgi/test +0 -9
  106. data/test/cgi/test+directory/test+file +0 -1
  107. data/test/cgi/test.fcgi +0 -8
  108. data/test/cgi/test.ru +0 -5
  109. data/test/gemloader.rb +0 -10
  110. data/test/multipart/bad_robots +0 -259
  111. data/test/multipart/binary +0 -0
  112. data/test/multipart/content_type_and_no_filename +0 -6
  113. data/test/multipart/empty +0 -10
  114. data/test/multipart/fail_16384_nofile +0 -814
  115. data/test/multipart/file1.txt +0 -1
  116. data/test/multipart/filename_and_modification_param +0 -7
  117. data/test/multipart/filename_and_no_name +0 -6
  118. data/test/multipart/filename_with_escaped_quotes +0 -6
  119. data/test/multipart/filename_with_escaped_quotes_and_modification_param +0 -7
  120. data/test/multipart/filename_with_null_byte +0 -7
  121. data/test/multipart/filename_with_percent_escaped_quotes +0 -6
  122. data/test/multipart/filename_with_unescaped_percentages +0 -6
  123. data/test/multipart/filename_with_unescaped_percentages2 +0 -6
  124. data/test/multipart/filename_with_unescaped_percentages3 +0 -6
  125. data/test/multipart/filename_with_unescaped_quotes +0 -6
  126. data/test/multipart/ie +0 -6
  127. data/test/multipart/invalid_character +0 -6
  128. data/test/multipart/mixed_files +0 -21
  129. data/test/multipart/nested +0 -10
  130. data/test/multipart/none +0 -9
  131. data/test/multipart/semicolon +0 -6
  132. data/test/multipart/text +0 -15
  133. data/test/multipart/three_files_three_fields +0 -31
  134. data/test/multipart/webkit +0 -32
  135. data/test/rackup/config.ru +0 -31
  136. data/test/registering_handler/rack/handler/registering_myself.rb +0 -8
  137. data/test/spec_auth_basic.rb +0 -81
  138. data/test/spec_auth_digest.rb +0 -259
  139. data/test/spec_body_proxy.rb +0 -85
  140. data/test/spec_builder.rb +0 -223
  141. data/test/spec_cascade.rb +0 -61
  142. data/test/spec_cgi.rb +0 -102
  143. data/test/spec_chunked.rb +0 -101
  144. data/test/spec_commonlogger.rb +0 -93
  145. data/test/spec_conditionalget.rb +0 -102
  146. data/test/spec_config.rb +0 -22
  147. data/test/spec_content_length.rb +0 -85
  148. data/test/spec_content_type.rb +0 -45
  149. data/test/spec_deflater.rb +0 -339
  150. data/test/spec_directory.rb +0 -88
  151. data/test/spec_etag.rb +0 -107
  152. data/test/spec_fastcgi.rb +0 -107
  153. data/test/spec_file.rb +0 -221
  154. data/test/spec_handler.rb +0 -72
  155. data/test/spec_head.rb +0 -45
  156. data/test/spec_lint.rb +0 -550
  157. data/test/spec_lobster.rb +0 -58
  158. data/test/spec_lock.rb +0 -164
  159. data/test/spec_logger.rb +0 -23
  160. data/test/spec_methodoverride.rb +0 -111
  161. data/test/spec_mime.rb +0 -51
  162. data/test/spec_mock.rb +0 -297
  163. data/test/spec_mongrel.rb +0 -182
  164. data/test/spec_multipart.rb +0 -600
  165. data/test/spec_nulllogger.rb +0 -20
  166. data/test/spec_recursive.rb +0 -72
  167. data/test/spec_request.rb +0 -1232
  168. data/test/spec_response.rb +0 -407
  169. data/test/spec_rewindable_input.rb +0 -118
  170. data/test/spec_runtime.rb +0 -49
  171. data/test/spec_sendfile.rb +0 -130
  172. data/test/spec_server.rb +0 -167
  173. data/test/spec_session_abstract_id.rb +0 -53
  174. data/test/spec_session_cookie.rb +0 -410
  175. data/test/spec_session_memcache.rb +0 -321
  176. data/test/spec_session_pool.rb +0 -209
  177. data/test/spec_showexceptions.rb +0 -98
  178. data/test/spec_showstatus.rb +0 -103
  179. data/test/spec_static.rb +0 -145
  180. data/test/spec_tempfile_reaper.rb +0 -63
  181. data/test/spec_thin.rb +0 -91
  182. data/test/spec_urlmap.rb +0 -236
  183. data/test/spec_utils.rb +0 -647
  184. data/test/spec_version.rb +0 -17
  185. data/test/spec_webrick.rb +0 -184
  186. data/test/static/another/index.html +0 -1
  187. data/test/static/index.html +0 -1
  188. data/test/testrequest.rb +0 -78
  189. data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
  190. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
data/test/spec_webrick.rb DELETED
@@ -1,184 +0,0 @@
1
- require 'rack/mock'
2
- require File.expand_path('../testrequest', __FILE__)
3
-
4
- Thread.abort_on_exception = true
5
-
6
- describe Rack::Handler::WEBrick do
7
- extend TestRequest::Helpers
8
-
9
- @server = WEBrick::HTTPServer.new(:Host => @host='127.0.0.1',
10
- :Port => @port=9202,
11
- :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
12
- :AccessLog => [])
13
- @server.mount "/test", Rack::Handler::WEBrick,
14
- Rack::Lint.new(TestRequest.new)
15
- Thread.new { @server.start }
16
- trap(:INT) { @server.shutdown }
17
-
18
- should "respond" do
19
- lambda {
20
- GET("/test")
21
- }.should.not.raise
22
- end
23
-
24
- should "be a WEBrick" do
25
- GET("/test")
26
- status.should.equal 200
27
- response["SERVER_SOFTWARE"].should =~ /WEBrick/
28
- response["HTTP_VERSION"].should.equal "HTTP/1.1"
29
- response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
30
- response["SERVER_PORT"].should.equal "9202"
31
- response["SERVER_NAME"].should.equal "127.0.0.1"
32
- end
33
-
34
- should "have rack headers" do
35
- GET("/test")
36
- response["rack.version"].should.equal [1,3]
37
- response["rack.multithread"].should.be.true
38
- response["rack.multiprocess"].should.be.false
39
- response["rack.run_once"].should.be.false
40
- end
41
-
42
- should "have CGI headers on GET" do
43
- GET("/test")
44
- response["REQUEST_METHOD"].should.equal "GET"
45
- response["SCRIPT_NAME"].should.equal "/test"
46
- response["REQUEST_PATH"].should.equal "/test"
47
- response["PATH_INFO"].should.be.equal ""
48
- response["QUERY_STRING"].should.equal ""
49
- response["test.postdata"].should.equal ""
50
-
51
- GET("/test/foo?quux=1")
52
- response["REQUEST_METHOD"].should.equal "GET"
53
- response["SCRIPT_NAME"].should.equal "/test"
54
- response["REQUEST_PATH"].should.equal "/test/foo"
55
- response["PATH_INFO"].should.equal "/foo"
56
- response["QUERY_STRING"].should.equal "quux=1"
57
-
58
- GET("/test/foo%25encoding?quux=1")
59
- response["REQUEST_METHOD"].should.equal "GET"
60
- response["SCRIPT_NAME"].should.equal "/test"
61
- response["REQUEST_PATH"].should.equal "/test/foo%25encoding"
62
- response["PATH_INFO"].should.equal "/foo%25encoding"
63
- response["QUERY_STRING"].should.equal "quux=1"
64
- end
65
-
66
- should "have CGI headers on POST" do
67
- POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
68
- status.should.equal 200
69
- response["REQUEST_METHOD"].should.equal "POST"
70
- response["SCRIPT_NAME"].should.equal "/test"
71
- response["REQUEST_PATH"].should.equal "/test"
72
- response["PATH_INFO"].should.equal ""
73
- response["QUERY_STRING"].should.equal ""
74
- response["HTTP_X_TEST_HEADER"].should.equal "42"
75
- response["test.postdata"].should.equal "rack-form-data=23"
76
- end
77
-
78
- should "support HTTP auth" do
79
- GET("/test", {:user => "ruth", :passwd => "secret"})
80
- response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
81
- end
82
-
83
- should "set status" do
84
- GET("/test?secret")
85
- status.should.equal 403
86
- response["rack.url_scheme"].should.equal "http"
87
- end
88
-
89
- should "correctly set cookies" do
90
- @server.mount "/cookie-test", Rack::Handler::WEBrick,
91
- Rack::Lint.new(lambda { |req|
92
- res = Rack::Response.new
93
- res.set_cookie "one", "1"
94
- res.set_cookie "two", "2"
95
- res.finish
96
- })
97
-
98
- Net::HTTP.start(@host, @port) { |http|
99
- res = http.get("/cookie-test")
100
- res.code.to_i.should.equal 200
101
- res.get_fields("set-cookie").should.equal ["one=1", "two=2"]
102
- }
103
- end
104
-
105
- should "provide a .run" do
106
- block_ran = false
107
- catch(:done) {
108
- Rack::Handler::WEBrick.run(lambda {},
109
- {
110
- :Host => '127.0.0.1',
111
- :Port => 9210,
112
- :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
113
- :AccessLog => []}) { |server|
114
- block_ran = true
115
- server.should.be.kind_of WEBrick::HTTPServer
116
- @s = server
117
- throw :done
118
- }
119
- }
120
- block_ran.should.be.true
121
- @s.shutdown
122
- end
123
-
124
- should "return repeated headers" do
125
- @server.mount "/headers", Rack::Handler::WEBrick,
126
- Rack::Lint.new(lambda { |req|
127
- [
128
- 401,
129
- { "Content-Type" => "text/plain",
130
- "WWW-Authenticate" => "Bar realm=X\nBaz realm=Y" },
131
- [""]
132
- ]
133
- })
134
-
135
- Net::HTTP.start(@host, @port) { |http|
136
- res = http.get("/headers")
137
- res.code.to_i.should.equal 401
138
- res["www-authenticate"].should.equal "Bar realm=X, Baz realm=Y"
139
- }
140
- end
141
-
142
- should "support Rack partial hijack" do
143
- io_lambda = lambda{ |io|
144
- 5.times do
145
- io.write "David\r\n"
146
- end
147
- io.close
148
- }
149
-
150
- @server.mount "/partial", Rack::Handler::WEBrick,
151
- Rack::Lint.new(lambda{ |req|
152
- [
153
- 200,
154
- {"rack.hijack" => io_lambda},
155
- [""]
156
- ]
157
- })
158
-
159
- Net::HTTP.start(@host, @port){ |http|
160
- res = http.get("/partial")
161
- res.body.should.equal "David\r\nDavid\r\nDavid\r\nDavid\r\nDavid\r\n"
162
- }
163
- end
164
-
165
- should "produce correct HTTP semantics with and without app chunking" do
166
- @server.mount "/chunked", Rack::Handler::WEBrick,
167
- Rack::Lint.new(lambda{ |req|
168
- [
169
- 200,
170
- {"Transfer-Encoding" => "chunked"},
171
- ["7\r\nchunked\r\n0\r\n\r\n"]
172
- ]
173
- })
174
-
175
- Net::HTTP.start(@host, @port){ |http|
176
- res = http.get("/chunked")
177
- res["Transfer-Encoding"].should.equal "chunked"
178
- res["Content-Length"].should.equal nil
179
- res.body.should.equal "chunked"
180
- }
181
- end
182
-
183
- @server.shutdown
184
- end
@@ -1 +0,0 @@
1
- another index!
@@ -1 +0,0 @@
1
- index!
data/test/testrequest.rb DELETED
@@ -1,78 +0,0 @@
1
- require 'yaml'
2
- require 'net/http'
3
- require 'rack/lint'
4
-
5
- class TestRequest
6
- NOSERIALIZE = [Method, Proc, Rack::Lint::InputWrapper]
7
-
8
- def call(env)
9
- status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200
10
- env["test.postdata"] = env["rack.input"].read
11
- minienv = env.dup
12
- # This may in the future want to replace with a dummy value instead.
13
- minienv.delete_if { |k,v| NOSERIALIZE.any? { |c| v.kind_of?(c) } }
14
- body = minienv.to_yaml
15
- size = body.respond_to?(:bytesize) ? body.bytesize : body.size
16
- [status, {"Content-Type" => "text/yaml", "Content-Length" => size.to_s}, [body]]
17
- end
18
-
19
- module Helpers
20
- attr_reader :status, :response
21
-
22
- ROOT = File.expand_path(File.dirname(__FILE__) + "/..")
23
- ENV["RUBYOPT"] = "-I#{ROOT}/lib -rubygems"
24
-
25
- def root
26
- ROOT
27
- end
28
-
29
- def rackup
30
- "#{ROOT}/bin/rackup"
31
- end
32
-
33
- def GET(path, header={})
34
- Net::HTTP.start(@host, @port) { |http|
35
- user = header.delete(:user)
36
- passwd = header.delete(:passwd)
37
-
38
- get = Net::HTTP::Get.new(path, header)
39
- get.basic_auth user, passwd if user && passwd
40
- http.request(get) { |response|
41
- @status = response.code.to_i
42
- begin
43
- @response = YAML.load(response.body)
44
- rescue TypeError, ArgumentError
45
- @response = nil
46
- end
47
- }
48
- }
49
- end
50
-
51
- def POST(path, formdata={}, header={})
52
- Net::HTTP.start(@host, @port) { |http|
53
- user = header.delete(:user)
54
- passwd = header.delete(:passwd)
55
-
56
- post = Net::HTTP::Post.new(path, header)
57
- post.form_data = formdata
58
- post.basic_auth user, passwd if user && passwd
59
- http.request(post) { |response|
60
- @status = response.code.to_i
61
- @response = YAML.load(response.body)
62
- }
63
- }
64
- end
65
- end
66
- end
67
-
68
- class StreamingRequest
69
- def self.call(env)
70
- [200, {"Content-Type" => "text/plain"}, new]
71
- end
72
-
73
- def each
74
- yield "hello there!\n"
75
- sleep 5
76
- yield "that is all.\n"
77
- end
78
- end
@@ -1,7 +0,0 @@
1
- module Rack
2
- module Handler
3
- # this class doesn't do anything, we're just seeing if we get it.
4
- class Unregistered
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module Rack
2
- module Handler
3
- # this class doesn't do anything, we're just seeing if we get it.
4
- class UnregisteredLongOne
5
- end
6
- end
7
- end