rack-contrib 1.8.0 → 2.3.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-contrib might be problematic. Click here for more details.

Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +17 -10
  3. data/lib/rack/contrib.rb +3 -3
  4. data/lib/rack/contrib/access.rb +6 -4
  5. data/lib/rack/contrib/backstage.rb +3 -1
  6. data/lib/rack/contrib/bounce_favicon.rb +2 -0
  7. data/lib/rack/contrib/callbacks.rb +2 -0
  8. data/lib/rack/contrib/common_cookies.rb +16 -11
  9. data/lib/rack/contrib/config.rb +3 -15
  10. data/lib/rack/contrib/cookies.rb +2 -0
  11. data/lib/rack/contrib/csshttprequest.rb +10 -6
  12. data/lib/rack/contrib/deflect.rb +34 -32
  13. data/lib/rack/contrib/enforce_valid_encoding.rb +2 -0
  14. data/lib/rack/contrib/evil.rb +2 -0
  15. data/lib/rack/contrib/expectation_cascade.rb +3 -1
  16. data/lib/rack/contrib/garbagecollector.rb +2 -0
  17. data/lib/rack/contrib/host_meta.rb +2 -0
  18. data/lib/rack/contrib/json_body_parser.rb +85 -0
  19. data/lib/rack/contrib/jsonp.rb +8 -6
  20. data/lib/rack/contrib/lazy_conditional_get.rb +9 -0
  21. data/lib/rack/contrib/lighttpd_script_name_fix.rb +2 -0
  22. data/lib/rack/contrib/locale.rb +65 -30
  23. data/lib/rack/contrib/mailexceptions.rb +4 -2
  24. data/lib/rack/contrib/nested_params.rb +6 -121
  25. data/lib/rack/contrib/not_found.rb +3 -1
  26. data/lib/rack/contrib/post_body_content_type_parser.rb +49 -4
  27. data/lib/rack/contrib/printout.rb +2 -0
  28. data/lib/rack/contrib/proctitle.rb +2 -0
  29. data/lib/rack/contrib/profiler.rb +6 -1
  30. data/lib/rack/contrib/relative_redirect.rb +10 -5
  31. data/lib/rack/contrib/response_cache.rb +22 -11
  32. data/lib/rack/contrib/response_headers.rb +2 -0
  33. data/lib/rack/contrib/route_exceptions.rb +2 -0
  34. data/lib/rack/contrib/runtime.rb +3 -30
  35. data/lib/rack/contrib/signals.rb +6 -0
  36. data/lib/rack/contrib/simple_endpoint.rb +3 -1
  37. data/lib/rack/contrib/static_cache.rb +17 -8
  38. data/lib/rack/contrib/time_zone.rb +2 -0
  39. data/lib/rack/contrib/try_static.rb +2 -0
  40. metadata +50 -32
  41. data/lib/rack/contrib/accept_format.rb +0 -66
  42. data/lib/rack/contrib/sendfile.rb +0 -138
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  #prints the environment and request for simple debugging
3
5
  class Printout
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  # Middleware to update the process title ($0) with information about the
3
5
  # current request. Based loosely on:
@@ -1,10 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby-prof'
2
4
 
3
5
  module Rack
4
6
  # Set the profile=process_time query parameter to download a
5
7
  # calltree profile of the request.
6
8
  #
7
- # Pass the :printer option to pick a different result format.
9
+ # Pass the :printer option to pick a different result format. Note that
10
+ # some printers (such as CallTreePrinter) have broken the
11
+ # `AbstractPrinter` API, and thus will not work. Bug reports to
12
+ # `ruby-prof`, please, not us.
8
13
  #
9
14
  # You can cause every request to be run multiple times by passing the
10
15
  # `:times` option to the `use Rack::Profiler` call. You can also run a
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rack'
2
4
 
3
5
  # Rack::RelativeRedirect is a simple middleware that converts relative paths in
@@ -30,15 +32,18 @@ class Rack::RelativeRedirect
30
32
  # and use that to make the Location header an absolute url. If the Location
31
33
  # does not start with a slash, make location relative to the path requested.
32
34
  def call(env)
33
- res = @app.call(env)
34
- if [301,302,303, 307,308].include?(res[0]) and loc = res[1]['Location'] and !%r{\Ahttps?://}o.match(loc)
35
- absolute = @absolute_proc.call(env, res)
36
- res[1]['Location'] = if %r{\A/}.match(loc)
35
+ status, headers, body = @app.call(env)
36
+ headers = Rack::Utils::HeaderHash.new(headers)
37
+
38
+ if [301,302,303, 307,308].include?(status) and loc = headers['Location'] and !%r{\Ahttps?://}o.match(loc)
39
+ absolute = @absolute_proc.call(env, [status, headers, body])
40
+ headers['Location'] = if %r{\A/}.match(loc)
37
41
  "#{absolute}#{loc}"
38
42
  else
39
43
  "#{absolute}#{File.dirname(Rack::Utils.unescape(env['PATH_INFO']))}/#{loc}"
40
44
  end
41
45
  end
42
- res
46
+
47
+ [status, headers, body]
43
48
  end
44
49
  end
@@ -1,11 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'rack'
3
5
 
4
6
  # Rack::ResponseCache is a Rack middleware that caches responses for successful
5
7
  # GET requests with no query string to disk or any ruby object that has an
6
- # []= method (so it works with memcached). When caching to disk, it works similar to
7
- # Rails' page caching, allowing you to cache dynamic pages to static files that can
8
- # be served directly by a front end webserver.
8
+ # []= method (so it works with memcached). As with Rails' page caching, this
9
+ # middleware only writes to the cache -- it never reads. The logic of whether a
10
+ # cached response should be served is left either to your web server, via
11
+ # something like the <tt>try_files</tt> directive in nginx, or to your
12
+ # cache-reading middleware of choice, mounted before Rack::ResponseCache in the
13
+ # stack.
9
14
  class Rack::ResponseCache
10
15
  # The default proc used if a block is not provided to .new
11
16
  # It unescapes the PATH_INFO of the environment, and makes sure that it doesn't
@@ -15,7 +20,10 @@ class Rack::ResponseCache
15
20
  # of the path to index.html.
16
21
  DEFAULT_PATH_PROC = proc do |env, res|
17
22
  path = Rack::Utils.unescape(env['PATH_INFO'])
18
- if !path.include?('..') and match = /text\/((?:x|ht)ml|css)/o.match(res[1]['Content-Type'])
23
+ headers = res[1]
24
+ content_type = headers['Content-Type']
25
+
26
+ if !path.include?('..') and match = /text\/((?:x|ht)ml|css)/o.match(content_type)
19
27
  type = match[1]
20
28
  path = "#{path}.#{type}" unless /\.#{type}\z/.match(path)
21
29
  path = File.join(File.dirname(path), 'index.html') if type == 'html' and File.basename(path) == '.html'
@@ -23,7 +31,7 @@ class Rack::ResponseCache
23
31
  end
24
32
  end
25
33
 
26
- # Initialize a new ReponseCache object with the given arguments. Arguments:
34
+ # Initialize a new ResponseCache object with the given arguments. Arguments:
27
35
  # * app : The next middleware in the chain. This is always called.
28
36
  # * cache : The place to cache responses. If a string is provided, a disk
29
37
  # cache is used, and all cached files will use this directory as the root directory.
@@ -42,18 +50,21 @@ class Rack::ResponseCache
42
50
  # Call the next middleware with the environment. If the request was successful (response status 200),
43
51
  # was a GET request, and had an empty query string, call the block set up in initialize to get the path.
44
52
  # If the cache is a string, create any necessary middle directories, and cache the file in the appropriate
45
- # subdirectory of cache. Otherwise, cache the body of the reponse as the value with the path as the key.
53
+ # subdirectory of cache. Otherwise, cache the body of the response as the value with the path as the key.
46
54
  def call(env)
47
- res = @app.call(env)
48
- if env['REQUEST_METHOD'] == 'GET' and env['QUERY_STRING'] == '' and res[0] == 200 and path = @path_proc.call(env, res)
55
+ status, headers, body = @app.call(env)
56
+ headers = Rack::Utils::HeaderHash.new(headers)
57
+
58
+ if env['REQUEST_METHOD'] == 'GET' and env['QUERY_STRING'] == '' and status == 200 and path = @path_proc.call(env, [status, headers, body])
49
59
  if @cache.is_a?(String)
50
60
  path = File.join(@cache, path) if @cache
51
61
  FileUtils.mkdir_p(File.dirname(path))
52
- File.open(path, 'wb'){|f| res[2].each{|c| f.write(c)}}
62
+ File.open(path, 'wb'){|f| body.each{|c| f.write(c)}}
53
63
  else
54
- @cache[path] = res[2]
64
+ @cache[path] = body
55
65
  end
56
66
  end
57
- res
67
+
68
+ [status, headers, body]
58
69
  end
59
70
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  # Allows you to tap into the response headers. Yields a Rack::Utils::HeaderHash
3
5
  # of current response headers to the block. Example:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class RouteExceptions
3
5
  ROUTES = [
@@ -1,31 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
- module Rack
3
- # Sets an "X-Runtime" response header, indicating the response
4
- # time of the request, in seconds
5
- #
6
- # You can put it right before the application to see the processing
7
- # time, or before all the other middlewares to include time for them,
8
- # too.
9
- class Runtime
10
- def initialize(app, name = nil)
11
- @app = app
12
- @header_name = "X-Runtime"
13
- @header_name << "-#{name}" if name
14
- end
15
-
16
- def call(env)
17
- start_time = Time.now
18
- status, headers, body = @app.call(env)
19
- request_time = Time.now - start_time
20
-
21
- if !headers.has_key?(@header_name)
22
- headers[@header_name] = "%0.6f" % request_time
23
- end
24
-
25
- [status, headers, body]
26
- end
27
- end
28
- end
29
-
30
-
31
-
3
+ require 'rack'
4
+ require 'rack/runtime'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  # Installs signal handlers that are safely processed after a request
3
5
  #
@@ -24,6 +26,10 @@ module Rack
24
26
  @body.each(&block)
25
27
  @callback.call
26
28
  end
29
+
30
+ def close
31
+ @body.close if @body.respond_to?(:close)
32
+ end
27
33
  end
28
34
 
29
35
  def initialize(app, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  # Create simple endpoints with routing rules, similar to Sinatra actions.
3
5
  #
@@ -78,4 +80,4 @@ module Rack
78
80
  @verbs.empty? || @verbs.include?(method)
79
81
  end
80
82
  end
81
- end
83
+ end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
1
5
  module Rack
2
6
 
3
7
  #
@@ -16,7 +20,7 @@ module Rack
16
20
  #
17
21
  # Another way to bypass the cache is adding the version number in a field-value pair in the
18
22
  # URL query string. As an example, http://yoursite.com/images/test.png?v=1.0.0
19
- # In that case, set the option :versioning to false to avoid unneccessary regexp calculations.
23
+ # In that case, set the option :versioning to false to avoid unnecessary regexp calculations.
20
24
  #
21
25
  # It's better to keep the current version number in some config file and use it in every static
22
26
  # content's URL. So each time we modify our static contents, we just have to change the version
@@ -40,7 +44,7 @@ module Rack
40
44
  # default headers.
41
45
  #
42
46
  # use Rack::StaticCache, :urls => ["/images"], :duration => 2, :versioning => false
43
- # will serve all requests begining with /images under the current directory (default for the option :root
47
+ # will serve all requests beginning with /images under the current directory (default for the option :root
44
48
  # is current directory). All the contents served will have cache expiration duration set to 2 years in headers
45
49
  # (default for :duration is 1 year), and StaticCache will not compute any versioning logics (default for
46
50
  # :versioning is true)
@@ -55,10 +59,12 @@ module Rack
55
59
  @no_cache = {}
56
60
  @urls.collect! do |url|
57
61
  if url =~ /\*$/
58
- url.sub!(/\*$/, '')
59
- @no_cache[url] = 1
62
+ url_prefix = url.sub(/\*$/, '')
63
+ @no_cache[url_prefix] = 1
64
+ url_prefix
65
+ else
66
+ url
60
67
  end
61
- url
62
68
  end
63
69
  root = options[:root] || Dir.pwd
64
70
  @file_server = Rack::File.new(root)
@@ -68,7 +74,6 @@ module Rack
68
74
  @version_regex = options.fetch(:version_regex, /-[\d.]+([.][a-zA-Z][\w]+)?$/)
69
75
  end
70
76
  @duration_in_seconds = self.duration_in_seconds
71
- @duration_in_words = self.duration_in_words
72
77
  end
73
78
 
74
79
  def call(env)
@@ -80,17 +85,21 @@ module Rack
80
85
  if @versioning_enabled
81
86
  path.sub!(@version_regex, '\1')
82
87
  end
88
+
83
89
  status, headers, body = @file_server.call(env)
90
+ headers = Utils::HeaderHash.new(headers)
91
+
84
92
  if @no_cache[url].nil?
85
93
  headers['Cache-Control'] ="max-age=#{@duration_in_seconds}, public"
86
- headers['Expires'] = @duration_in_words
94
+ headers['Expires'] = duration_in_words
87
95
  end
96
+ headers['Date'] = Time.now.httpdate
88
97
  [status, headers, body]
89
98
  end
90
99
  end
91
100
 
92
101
  def duration_in_words
93
- (Time.now + self.duration_in_seconds).strftime '%a, %d %b %Y %H:%M:%S GMT'
102
+ (Time.now.utc + self.duration_in_seconds).httpdate
94
103
  end
95
104
 
96
105
  def duration_in_seconds
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class TimeZone
3
5
  Javascript = <<-EOJ
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
 
3
5
  # The Rack::TryStatic middleware delegates requests to Rack::Static middleware
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rack-devel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -16,28 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3'
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '1.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: git-version-bump
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -72,54 +78,48 @@ dependencies:
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0.5'
81
+ version: '0.6'
76
82
  - - ">="
77
83
  - !ruby/object:Gem::Version
78
- version: 0.5.2
84
+ version: 0.6.8
79
85
  type: :development
80
86
  prerelease: false
81
87
  version_requirements: !ruby/object:Gem::Requirement
82
88
  requirements:
83
89
  - - "~>"
84
90
  - !ruby/object:Gem::Version
85
- version: '0.5'
91
+ version: '0.6'
86
92
  - - ">="
87
93
  - !ruby/object:Gem::Version
88
- version: 0.5.2
94
+ version: 0.6.8
89
95
  - !ruby/object:Gem::Dependency
90
96
  name: json
91
97
  requirement: !ruby/object:Gem::Requirement
92
98
  requirements:
93
99
  - - "~>"
94
100
  - !ruby/object:Gem::Version
95
- version: '1.8'
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: 1.8.5
101
+ version: '2.0'
99
102
  type: :development
100
103
  prerelease: false
101
104
  version_requirements: !ruby/object:Gem::Requirement
102
105
  requirements:
103
106
  - - "~>"
104
107
  - !ruby/object:Gem::Version
105
- version: '1.8'
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: 1.8.5
108
+ version: '2.0'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: mime-types
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "<"
113
+ - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: '3'
115
+ version: '3.0'
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "<"
120
+ - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '3'
122
+ version: '3.0'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: minitest
125
125
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +155,9 @@ dependencies:
155
155
  - - "~>"
156
156
  - !ruby/object:Gem::Version
157
157
  version: '2.3'
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.6.4
158
161
  type: :development
159
162
  prerelease: false
160
163
  version_requirements: !ruby/object:Gem::Requirement
@@ -162,6 +165,9 @@ dependencies:
162
165
  - - "~>"
163
166
  - !ruby/object:Gem::Version
164
167
  version: '2.3'
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: 2.6.4
165
171
  - !ruby/object:Gem::Dependency
166
172
  name: nbio-csshttprequest
167
173
  requirement: !ruby/object:Gem::Requirement
@@ -202,28 +208,42 @@ dependencies:
202
208
  requirements:
203
209
  - - "~>"
204
210
  - !ruby/object:Gem::Version
205
- version: '3.12'
211
+ version: '5.0'
206
212
  type: :development
207
213
  prerelease: false
208
214
  version_requirements: !ruby/object:Gem::Requirement
209
215
  requirements:
210
216
  - - "~>"
211
217
  - !ruby/object:Gem::Version
212
- version: '3.12'
218
+ version: '5.0'
213
219
  - !ruby/object:Gem::Dependency
214
220
  name: ruby-prof
215
221
  requirement: !ruby/object:Gem::Requirement
216
222
  requirements:
217
223
  - - "~>"
218
224
  - !ruby/object:Gem::Version
219
- version: 0.13.0
225
+ version: '0.17'
226
+ type: :development
227
+ prerelease: false
228
+ version_requirements: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - "~>"
231
+ - !ruby/object:Gem::Version
232
+ version: '0.17'
233
+ - !ruby/object:Gem::Dependency
234
+ name: timecop
235
+ requirement: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: '0.9'
220
240
  type: :development
221
241
  prerelease: false
222
242
  version_requirements: !ruby/object:Gem::Requirement
223
243
  requirements:
224
244
  - - "~>"
225
245
  - !ruby/object:Gem::Version
226
- version: 0.13.0
246
+ version: '0.9'
227
247
  description: Contributed Rack Middleware and Utilities
228
248
  email: rack-devel@googlegroups.com
229
249
  executables: []
@@ -236,7 +256,6 @@ files:
236
256
  - COPYING
237
257
  - README.md
238
258
  - lib/rack/contrib.rb
239
- - lib/rack/contrib/accept_format.rb
240
259
  - lib/rack/contrib/access.rb
241
260
  - lib/rack/contrib/backstage.rb
242
261
  - lib/rack/contrib/bounce_favicon.rb
@@ -251,6 +270,7 @@ files:
251
270
  - lib/rack/contrib/expectation_cascade.rb
252
271
  - lib/rack/contrib/garbagecollector.rb
253
272
  - lib/rack/contrib/host_meta.rb
273
+ - lib/rack/contrib/json_body_parser.rb
254
274
  - lib/rack/contrib/jsonp.rb
255
275
  - lib/rack/contrib/lazy_conditional_get.rb
256
276
  - lib/rack/contrib/lighttpd_script_name_fix.rb
@@ -267,13 +287,12 @@ files:
267
287
  - lib/rack/contrib/response_headers.rb
268
288
  - lib/rack/contrib/route_exceptions.rb
269
289
  - lib/rack/contrib/runtime.rb
270
- - lib/rack/contrib/sendfile.rb
271
290
  - lib/rack/contrib/signals.rb
272
291
  - lib/rack/contrib/simple_endpoint.rb
273
292
  - lib/rack/contrib/static_cache.rb
274
293
  - lib/rack/contrib/time_zone.rb
275
294
  - lib/rack/contrib/try_static.rb
276
- homepage: http://github.com/rack/rack-contrib/
295
+ homepage: https://github.com/rack/rack-contrib/
277
296
  licenses:
278
297
  - MIT
279
298
  metadata: {}
@@ -291,15 +310,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
291
310
  requirements:
292
311
  - - ">="
293
312
  - !ruby/object:Gem::Version
294
- version: '0'
313
+ version: 2.2.2
295
314
  required_rubygems_version: !ruby/object:Gem::Requirement
296
315
  requirements:
297
316
  - - ">="
298
317
  - !ruby/object:Gem::Version
299
318
  version: '0'
300
319
  requirements: []
301
- rubyforge_project:
302
- rubygems_version: 2.6.13
320
+ rubygems_version: 3.0.3
303
321
  signing_key:
304
322
  specification_version: 2
305
323
  summary: Contributed Rack Middleware and Utilities