rack-contrib 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0328244bd18e70963a841937904e3bf27eebfef5de80a4d3e1e09328e4c93ff8'
4
- data.tar.gz: 2ab61dc5347ad251d9654e3b94f705358081b8dd932b62a07cc95f42d611c3b3
3
+ metadata.gz: 1b83b23d3e67c0a24d65f6da2406e8430b003100bae5b5e8f3b20486384804e0
4
+ data.tar.gz: 4e2b5a6b94dbd7be2b10a6dae026509166d236e0b0e842f0a127b59d28298ae9
5
5
  SHA512:
6
- metadata.gz: 6a877560e6bfb9df7779a324fcbd803294fe9939563cd1360f27a93f377f567d35bb3ca28e9935e5f7d5babbb221082ba13abb4edf1819cc9e204f229840f41f
7
- data.tar.gz: f657d4a1f6846c3e426dea6f5ef3dcb62369c23ae36f4eaa1abe689b6210327fa78aa102058399397f1e1731d60f2070915479578026fa78c8e98470f1b5f843
6
+ metadata.gz: a12773ffdd9646740002b8124c2bd02bdc92d738ced7c4bb270e6003661a259d4dc8e34925bd909805bd1e40a0d381b9efa59c3d2d02d1fe5f9dcd57af8809c9
7
+ data.tar.gz: c9955bcfb8787a930d9590cc984ab16a25211e2f52b9fe76b7d357088bbc68503e1c2fc362c46ba0c8febb08aa73eb67ed04bd03ddbdea39bd489e336211d385
data/README.md CHANGED
@@ -76,7 +76,7 @@ To contribute to the project, begin by cloning the repo and installing the neces
76
76
 
77
77
  gem install json rack ruby-prof test-spec test-unit
78
78
 
79
- To run the entire test suite, run
79
+ To run the entire test suite, run
80
80
 
81
81
  rake test
82
82
 
@@ -84,7 +84,7 @@ To run a specific component's tests run
84
84
 
85
85
  specrb -Ilib:test -w test/spec_rack_thecomponent.rb
86
86
 
87
- This works on ruby 1.8.7 but has problems under ruby 1.9.x.
87
+ This works on ruby 1.8.7 but has problems under ruby 1.9.x.
88
88
 
89
89
  TODO: instructions for 1.9.x and include bundler
90
90
 
@@ -98,10 +98,16 @@ The criteria for middleware being included in this project are roughly as follow
98
98
  These criteria were introduced several years after the start of the project, so some of the included middleware may not meet all of them. In particular, several middleware have external dependencies. It is possible that in some future release of rack-contrib, middleware with external depencies will be removed from the project.
99
99
 
100
100
  When submitting code keep the above criteria in mind and also see the code
101
- guidelines in CONTRIBUTING.md.
101
+ guidelines in CONTRIBUTING.md.
102
102
 
103
103
  ### Links
104
104
 
105
105
  * rack-contrib on GitHub:: <https://github.com/rack/rack-contrib>
106
106
  * Rack:: <https://rack.github.io/>
107
107
  * Rack On GitHub:: <https://github.com/rack/rack>
108
+
109
+
110
+ ### Security Reporting
111
+
112
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
113
+ Tidelift will coordinate the fix and disclosure.
@@ -72,9 +72,12 @@ module Rack
72
72
 
73
73
  if I18n.enforce_available_locales
74
74
  locale = locales.reverse.find { |locale| I18n.available_locales.any? { |al| match?(al, locale) } }
75
- if locale
76
- I18n.available_locales.find { |al| match?(al, locale) }
75
+ matched_locale = I18n.available_locales.find { |al| match?(al, locale) } if locale
76
+ if !locale && !matched_locale
77
+ matched_locale = locales.reverse.find { |locale| I18n.available_locales.any? { |al| variant_match?(al, locale) } }
78
+ matched_locale = matched_locale[0,2] if matched_locale
77
79
  end
80
+ matched_locale
78
81
  else
79
82
  locales.last
80
83
  end
@@ -83,5 +86,9 @@ module Rack
83
86
  def match?(s1, s2)
84
87
  s1.to_s.casecmp(s2.to_s) == 0
85
88
  end
89
+
90
+ def variant_match?(s1, s2)
91
+ s1.to_s.casecmp(s2[0,2].to_s) == 0
92
+ end
86
93
  end
87
94
  end
@@ -35,8 +35,11 @@ module Rack
35
35
  @profile = nil
36
36
  @printer = parse_printer(options[:printer] || DEFAULT_PRINTER)
37
37
  @times = (options[:times] || 1).to_i
38
+ @maximum_runs = options.fetch(:maximum_runs, 10)
38
39
  end
39
40
 
41
+ attr :maximum_runs
42
+
40
43
  def call(env)
41
44
  if mode = profiling?(env)
42
45
  profile(env, mode)
@@ -61,14 +64,32 @@ module Rack
61
64
  end
62
65
  end
63
66
 
67
+ # How many times to run the request within the profiler.
68
+ # If the profiler_runs query parameter is set, use that.
69
+ # Otherwise, use the :times option passed to `#initialize`.
70
+ # If the profiler_runs query parameter is greater than the
71
+ # :maximum option passed to `#initialize`, use the :maximum
72
+ # option.
73
+ def runs(request)
74
+ if profiler_runs = request.params['profiler_runs']
75
+ profiler_runs = profiler_runs.to_i
76
+ if profiler_runs > @maximum_runs
77
+ return @maximum_runs
78
+ else
79
+ return profiler_runs
80
+ end
81
+ else
82
+ return @times
83
+ end
84
+ end
85
+
64
86
  def profile(env, mode)
65
87
  @profile = ::RubyProf::Profile.new(measure_mode: ::RubyProf.const_get(mode.upcase))
66
88
 
67
89
  GC.enable_stats if GC.respond_to?(:enable_stats)
68
90
  request = Rack::Request.new(env.clone)
69
- runs = (request.params['profiler_runs'] || @times).to_i
70
91
  result = @profile.profile do
71
- runs.times { @app.call(env) }
92
+ runs(request).times { @app.call(env) }
72
93
  end
73
94
  GC.disable_stats if GC.respond_to?(:disable_stats)
74
95
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Contrib
3
- VERSION = '2.4.0'
3
+ VERSION = '2.5.0'
4
4
  end
5
5
  end
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: 2.4.0
4
+ version: 2.5.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: 2023-10-24 00:00:00.000000000 Z
11
+ date: 2024-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.4.10
101
+ rubygems_version: 3.5.3
102
102
  signing_key:
103
103
  specification_version: 2
104
104
  summary: Contributed Rack Middleware and Utilities