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 +4 -4
- data/README.md +9 -3
- data/lib/rack/contrib/locale.rb +9 -2
- data/lib/rack/contrib/profiler.rb +23 -2
- data/lib/rack/contrib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b83b23d3e67c0a24d65f6da2406e8430b003100bae5b5e8f3b20486384804e0
|
4
|
+
data.tar.gz: 4e2b5a6b94dbd7be2b10a6dae026509166d236e0b0e842f0a127b59d28298ae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/lib/rack/contrib/locale.rb
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/rack/contrib/version.rb
CHANGED
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
|
+
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:
|
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.
|
101
|
+
rubygems_version: 3.5.3
|
102
102
|
signing_key:
|
103
103
|
specification_version: 2
|
104
104
|
summary: Contributed Rack Middleware and Utilities
|