rack 1.6.13 → 2.0.1

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 (144) hide show
  1. checksums.yaml +5 -5
  2. data/COPYING +1 -1
  3. data/HISTORY.md +138 -8
  4. data/README.rdoc +17 -25
  5. data/Rakefile +6 -14
  6. data/SPEC +8 -9
  7. data/contrib/rack_logo.svg +164 -111
  8. data/example/protectedlobster.rb +1 -1
  9. data/example/protectedlobster.ru +1 -1
  10. data/lib/rack/auth/abstract/request.rb +5 -1
  11. data/lib/rack/auth/digest/params.rb +2 -3
  12. data/lib/rack/auth/digest/request.rb +1 -1
  13. data/lib/rack/body_proxy.rb +14 -9
  14. data/lib/rack/builder.rb +3 -3
  15. data/lib/rack/chunked.rb +5 -5
  16. data/lib/rack/{commonlogger.rb → common_logger.rb} +3 -3
  17. data/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
  18. data/lib/rack/content_length.rb +2 -2
  19. data/lib/rack/deflater.rb +4 -4
  20. data/lib/rack/directory.rb +66 -54
  21. data/lib/rack/etag.rb +4 -3
  22. data/lib/rack/events.rb +154 -0
  23. data/lib/rack/file.rb +63 -39
  24. data/lib/rack/handler/cgi.rb +15 -16
  25. data/lib/rack/handler/fastcgi.rb +13 -14
  26. data/lib/rack/handler/lsws.rb +11 -11
  27. data/lib/rack/handler/scgi.rb +15 -15
  28. data/lib/rack/handler/thin.rb +3 -0
  29. data/lib/rack/handler/webrick.rb +22 -24
  30. data/lib/rack/handler.rb +3 -25
  31. data/lib/rack/head.rb +15 -17
  32. data/lib/rack/lint.rb +38 -38
  33. data/lib/rack/lobster.rb +1 -1
  34. data/lib/rack/lock.rb +6 -10
  35. data/lib/rack/logger.rb +2 -2
  36. data/lib/rack/media_type.rb +38 -0
  37. data/lib/rack/{methodoverride.rb → method_override.rb} +4 -11
  38. data/lib/rack/mime.rb +18 -5
  39. data/lib/rack/mock.rb +35 -53
  40. data/lib/rack/multipart/generator.rb +5 -5
  41. data/lib/rack/multipart/parser.rb +272 -158
  42. data/lib/rack/multipart/uploaded_file.rb +1 -2
  43. data/lib/rack/multipart.rb +35 -6
  44. data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
  45. data/lib/rack/query_parser.rb +192 -0
  46. data/lib/rack/recursive.rb +8 -8
  47. data/lib/rack/request.rb +383 -307
  48. data/lib/rack/response.rb +129 -56
  49. data/lib/rack/rewindable_input.rb +1 -12
  50. data/lib/rack/runtime.rb +10 -18
  51. data/lib/rack/sendfile.rb +5 -7
  52. data/lib/rack/server.rb +31 -25
  53. data/lib/rack/session/abstract/id.rb +95 -135
  54. data/lib/rack/session/cookie.rb +26 -28
  55. data/lib/rack/session/memcache.rb +8 -14
  56. data/lib/rack/session/pool.rb +14 -21
  57. data/lib/rack/show_exceptions.rb +386 -0
  58. data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
  59. data/lib/rack/static.rb +30 -5
  60. data/lib/rack/tempfile_reaper.rb +2 -2
  61. data/lib/rack/urlmap.rb +15 -14
  62. data/lib/rack/utils.rb +135 -210
  63. data/lib/rack.rb +70 -21
  64. data/rack.gemspec +7 -5
  65. data/test/builder/an_underscore_app.rb +5 -0
  66. data/test/builder/options.ru +1 -1
  67. data/test/cgi/test.fcgi +1 -0
  68. data/test/cgi/test.gz +0 -0
  69. data/test/helper.rb +34 -0
  70. data/test/multipart/filename_with_encoded_words +7 -0
  71. data/test/multipart/{filename_with_null_byte → filename_with_single_quote} +1 -1
  72. data/test/multipart/quoted +15 -0
  73. data/test/multipart/rack-logo.png +0 -0
  74. data/test/multipart/unity3d_wwwform +11 -0
  75. data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
  76. data/test/spec_auth_basic.rb +27 -19
  77. data/test/spec_auth_digest.rb +47 -46
  78. data/test/spec_body_proxy.rb +27 -27
  79. data/test/spec_builder.rb +51 -41
  80. data/test/spec_cascade.rb +24 -22
  81. data/test/spec_cgi.rb +49 -67
  82. data/test/spec_chunked.rb +36 -34
  83. data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
  84. data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
  85. data/test/spec_config.rb +3 -2
  86. data/test/spec_content_length.rb +18 -17
  87. data/test/spec_content_type.rb +13 -12
  88. data/test/spec_deflater.rb +66 -40
  89. data/test/spec_directory.rb +87 -27
  90. data/test/spec_etag.rb +32 -31
  91. data/test/spec_events.rb +133 -0
  92. data/test/spec_fastcgi.rb +50 -72
  93. data/test/spec_file.rb +107 -77
  94. data/test/spec_handler.rb +19 -34
  95. data/test/spec_head.rb +15 -14
  96. data/test/spec_lint.rb +162 -197
  97. data/test/spec_lobster.rb +24 -23
  98. data/test/spec_lock.rb +69 -39
  99. data/test/spec_logger.rb +4 -3
  100. data/test/spec_media_type.rb +42 -0
  101. data/test/spec_method_override.rb +83 -0
  102. data/test/spec_mime.rb +19 -19
  103. data/test/spec_mock.rb +196 -151
  104. data/test/spec_multipart.rb +317 -201
  105. data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
  106. data/test/spec_recursive.rb +17 -14
  107. data/test/spec_request.rb +768 -607
  108. data/test/spec_response.rb +214 -111
  109. data/test/spec_rewindable_input.rb +50 -40
  110. data/test/spec_runtime.rb +11 -10
  111. data/test/spec_sendfile.rb +30 -35
  112. data/test/spec_server.rb +78 -52
  113. data/test/spec_session_abstract_id.rb +11 -33
  114. data/test/spec_session_abstract_session_hash.rb +28 -0
  115. data/test/spec_session_cookie.rb +97 -65
  116. data/test/spec_session_memcache.rb +63 -101
  117. data/test/spec_session_pool.rb +48 -84
  118. data/test/spec_show_exceptions.rb +80 -0
  119. data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
  120. data/test/spec_static.rb +71 -32
  121. data/test/spec_tempfile_reaper.rb +11 -10
  122. data/test/spec_thin.rb +55 -50
  123. data/test/spec_urlmap.rb +79 -78
  124. data/test/spec_utils.rb +441 -346
  125. data/test/spec_version.rb +2 -8
  126. data/test/spec_webrick.rb +91 -67
  127. data/test/static/foo.html +1 -0
  128. data/test/testrequest.rb +1 -1
  129. data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
  130. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
  131. metadata +103 -69
  132. data/KNOWN-ISSUES +0 -44
  133. data/lib/rack/backports/uri/common_18.rb +0 -56
  134. data/lib/rack/backports/uri/common_192.rb +0 -52
  135. data/lib/rack/backports/uri/common_193.rb +0 -29
  136. data/lib/rack/handler/evented_mongrel.rb +0 -8
  137. data/lib/rack/handler/mongrel.rb +0 -106
  138. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  139. data/lib/rack/showexceptions.rb +0 -387
  140. data/lib/rack/utils/okjson.rb +0 -600
  141. data/test/spec_methodoverride.rb +0 -111
  142. data/test/spec_mongrel.rb +0 -182
  143. data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
  144. data/test/spec_showexceptions.rb +0 -98
data/lib/rack/mock.rb CHANGED
@@ -41,27 +41,27 @@ module Rack
41
41
  end
42
42
 
43
43
  DEFAULT_ENV = {
44
- "rack.version" => Rack::VERSION,
45
- "rack.input" => StringIO.new,
46
- "rack.errors" => StringIO.new,
47
- "rack.multithread" => true,
48
- "rack.multiprocess" => true,
49
- "rack.run_once" => false,
50
- }
44
+ RACK_VERSION => Rack::VERSION,
45
+ RACK_INPUT => StringIO.new,
46
+ RACK_ERRORS => StringIO.new,
47
+ RACK_MULTITHREAD => true,
48
+ RACK_MULTIPROCESS => true,
49
+ RACK_RUNONCE => false,
50
+ }.freeze
51
51
 
52
52
  def initialize(app)
53
53
  @app = app
54
54
  end
55
55
 
56
- def get(uri, opts={}) request("GET", uri, opts) end
57
- def post(uri, opts={}) request("POST", uri, opts) end
58
- def put(uri, opts={}) request("PUT", uri, opts) end
59
- def patch(uri, opts={}) request("PATCH", uri, opts) end
60
- def delete(uri, opts={}) request("DELETE", uri, opts) end
61
- def head(uri, opts={}) request("HEAD", uri, opts) end
62
- def options(uri, opts={}) request("OPTIONS", uri, opts) end
56
+ def get(uri, opts={}) request(GET, uri, opts) end
57
+ def post(uri, opts={}) request(POST, uri, opts) end
58
+ def put(uri, opts={}) request(PUT, uri, opts) end
59
+ def patch(uri, opts={}) request(PATCH, uri, opts) end
60
+ def delete(uri, opts={}) request(DELETE, uri, opts) end
61
+ def head(uri, opts={}) request(HEAD, uri, opts) end
62
+ def options(uri, opts={}) request(OPTIONS, uri, opts) end
63
63
 
64
- def request(method="GET", uri="", opts={})
64
+ def request(method=GET, uri="", opts={})
65
65
  env = self.class.env_for(uri, opts.merge(:method => method))
66
66
 
67
67
  if opts[:lint]
@@ -70,17 +70,17 @@ module Rack
70
70
  app = @app
71
71
  end
72
72
 
73
- errors = env["rack.errors"]
73
+ errors = env[RACK_ERRORS]
74
74
  status, headers, body = app.call(env)
75
75
  MockResponse.new(status, headers, body, errors)
76
76
  ensure
77
77
  body.close if body.respond_to?(:close)
78
78
  end
79
79
 
80
- # For historical reasons, we're pinning to RFC 2396. It's easier for users
81
- # and we get support from ruby 1.8 to 2.2 using this method.
80
+ # For historical reasons, we're pinning to RFC 2396.
81
+ # URI::Parser = URI::RFC2396_Parser
82
82
  def self.parse_uri_rfc2396(uri)
83
- @parser ||= defined?(URI::RFC2396_Parser) ? URI::RFC2396_Parser.new : URI
83
+ @parser ||= URI::Parser.new
84
84
  @parser.parse(uri)
85
85
  end
86
86
 
@@ -91,28 +91,34 @@ module Rack
91
91
 
92
92
  env = DEFAULT_ENV.dup
93
93
 
94
- env_with_encoding(env, opts, uri)
94
+ env[REQUEST_METHOD] = opts[:method] ? opts[:method].to_s.upcase : GET
95
+ env[SERVER_NAME] = uri.host || "example.org"
96
+ env[SERVER_PORT] = uri.port ? uri.port.to_s : "80"
97
+ env[QUERY_STRING] = uri.query.to_s
98
+ env[PATH_INFO] = (!uri.path || uri.path.empty?) ? "/" : uri.path
99
+ env[RACK_URL_SCHEME] = uri.scheme || "http"
100
+ env[HTTPS] = env[RACK_URL_SCHEME] == "https" ? "on" : "off"
95
101
 
96
102
  env[SCRIPT_NAME] = opts[:script_name] || ""
97
103
 
98
104
  if opts[:fatal]
99
- env["rack.errors"] = FatalWarner.new
105
+ env[RACK_ERRORS] = FatalWarner.new
100
106
  else
101
- env["rack.errors"] = StringIO.new
107
+ env[RACK_ERRORS] = StringIO.new
102
108
  end
103
109
 
104
110
  if params = opts[:params]
105
- if env[REQUEST_METHOD] == "GET"
111
+ if env[REQUEST_METHOD] == GET
106
112
  params = Utils.parse_nested_query(params) if params.is_a?(String)
107
113
  params.update(Utils.parse_nested_query(env[QUERY_STRING]))
108
114
  env[QUERY_STRING] = Utils.build_nested_query(params)
109
115
  elsif !opts.has_key?(:input)
110
116
  opts["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
111
117
  if params.is_a?(Hash)
112
- if data = Utils::Multipart.build_multipart(params)
118
+ if data = Rack::Multipart.build_multipart(params)
113
119
  opts[:input] = data
114
120
  opts["CONTENT_LENGTH"] ||= data.length.to_s
115
- opts["CONTENT_TYPE"] = "multipart/form-data; boundary=#{Utils::Multipart::MULTIPART_BOUNDARY}"
121
+ opts["CONTENT_TYPE"] = "multipart/form-data; boundary=#{Rack::Multipart::MULTIPART_BOUNDARY}"
116
122
  else
117
123
  opts[:input] = Utils.build_nested_query(params)
118
124
  end
@@ -122,8 +128,7 @@ module Rack
122
128
  end
123
129
  end
124
130
 
125
- empty_str = ""
126
- empty_str.force_encoding("ASCII-8BIT") if empty_str.respond_to? :force_encoding
131
+ empty_str = String.new.force_encoding(Encoding::ASCII_8BIT)
127
132
  opts[:input] ||= empty_str
128
133
  if String === opts[:input]
129
134
  rack_input = StringIO.new(opts[:input])
@@ -131,10 +136,10 @@ module Rack
131
136
  rack_input = opts[:input]
132
137
  end
133
138
 
134
- rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
135
- env['rack.input'] = rack_input
139
+ rack_input.set_encoding(Encoding::BINARY)
140
+ env[RACK_INPUT] = rack_input
136
141
 
137
- env["CONTENT_LENGTH"] ||= env["rack.input"].length.to_s
142
+ env["CONTENT_LENGTH"] ||= env[RACK_INPUT].length.to_s
138
143
 
139
144
  opts.each { |field, value|
140
145
  env[field] = value if String === field
@@ -142,28 +147,6 @@ module Rack
142
147
 
143
148
  env
144
149
  end
145
-
146
- if "<3".respond_to? :b
147
- def self.env_with_encoding(env, opts, uri)
148
- env[REQUEST_METHOD] = (opts[:method] ? opts[:method].to_s.upcase : "GET").b
149
- env["SERVER_NAME"] = (uri.host || "example.org").b
150
- env["SERVER_PORT"] = (uri.port ? uri.port.to_s : "80").b
151
- env[QUERY_STRING] = (uri.query.to_s).b
152
- env[PATH_INFO] = ((!uri.path || uri.path.empty?) ? "/" : uri.path).b
153
- env["rack.url_scheme"] = (uri.scheme || "http").b
154
- env["HTTPS"] = (env["rack.url_scheme"] == "https" ? "on" : "off").b
155
- end
156
- else
157
- def self.env_with_encoding(env, opts, uri)
158
- env[REQUEST_METHOD] = opts[:method] ? opts[:method].to_s.upcase : "GET"
159
- env["SERVER_NAME"] = uri.host || "example.org"
160
- env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80"
161
- env[QUERY_STRING] = uri.query.to_s
162
- env[PATH_INFO] = (!uri.path || uri.path.empty?) ? "/" : uri.path
163
- env["rack.url_scheme"] = uri.scheme || "http"
164
- env["HTTPS"] = env["rack.url_scheme"] == "https" ? "on" : "off"
165
- end
166
- end
167
150
  end
168
151
 
169
152
  # Rack::MockResponse provides useful helpers for testing your apps.
@@ -180,7 +163,6 @@ module Rack
180
163
  def initialize(status, headers, body, errors=StringIO.new(""))
181
164
  @original_headers = headers
182
165
  @errors = errors.string if errors.respond_to?(:string)
183
- @body_string = nil
184
166
 
185
167
  super(body, status, headers)
186
168
  end
@@ -11,18 +11,18 @@ module Rack
11
11
 
12
12
  def dump
13
13
  return nil if @first && !multipart?
14
- return flattened_params if !@first
14
+ return flattened_params unless @first
15
15
 
16
16
  flattened_params.map do |name, file|
17
17
  if file.respond_to?(:original_filename)
18
- ::File.open(file.path, "rb") do |f|
19
- f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding)
18
+ ::File.open(file.path, 'rb') do |f|
19
+ f.set_encoding(Encoding::BINARY)
20
20
  content_for_tempfile(f, file, name)
21
21
  end
22
22
  else
23
23
  content_for_other(file, name)
24
24
  end
25
- end.join + "--#{MULTIPART_BOUNDARY}--\r"
25
+ end.join << "--#{MULTIPART_BOUNDARY}--\r"
26
26
  end
27
27
 
28
28
  private
@@ -90,4 +90,4 @@ EOF
90
90
  end
91
91
  end
92
92
  end
93
- end
93
+ end