http-negotiate 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/http/negotiate/version.rb +1 -1
- data/lib/http/negotiate.rb +8 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d699dd657fff5ae1a330a54f83b33b9d091a455e052566270e3ff697e4eedc97
|
4
|
+
data.tar.gz: baae101cbbe136cf67f698eb4fb6990fc43e6194f4dbebcd7acc786911ec5c2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef0b67b2cb482168f9effe5900efb1f1be8c24a42fde4ddb3d51669b950d63e42f651c5b5cd6062172dff940ad4b27741b24648560a7d72343354969bdb7bafb
|
7
|
+
data.tar.gz: bd297a0bb246293fb405da83eafdf5226ffd38aedabf648c1d88234177c12a63a59e9cdb0ca7dc6e0462b0a1c4ac55707ffa0a8a4fd6cbe74fc53f0dd0ebec42
|
data/lib/http/negotiate.rb
CHANGED
@@ -55,18 +55,19 @@ module HTTP::Negotiate
|
|
55
55
|
# theoretically you can have quoted-string parameter values
|
56
56
|
# but we don't care (although interestingly according to rfc7231,
|
57
57
|
# accept-language only affords q= and not arbitrary parameters)
|
58
|
-
hdr = hdr.dup.
|
58
|
+
hdr = hdr.respond_to?(:to_a) ? hdr.to_a.dup : hdr.to_s.split(/\s*,+\s*/)
|
59
|
+
hdr = hdr.map { |h| h.to_s.gsub(/\s+/, '') }.reject(&:empty?)
|
59
60
|
|
60
61
|
# don't add the test group if it's an empty string, because
|
61
62
|
# postel's law is a thing
|
62
63
|
next if hdr.empty?
|
63
64
|
|
64
|
-
accept[k] = hdr.
|
65
|
+
accept[k] = hdr.map do |c|
|
65
66
|
val, *params = c.split(/;+/)
|
66
67
|
params = params.map do |p|
|
67
|
-
k, v = p.split(
|
68
|
+
k, v = p.split(/\s*=+\s*/, 2)
|
68
69
|
k = k.downcase.to_sym
|
69
|
-
v = v.to_f if v and k == :q
|
70
|
+
v = v.to_f if v and k == :q # note garbage will return 0
|
70
71
|
[k, v]
|
71
72
|
end.to_h
|
72
73
|
if params[:q]
|
@@ -228,12 +229,14 @@ module HTTP::Negotiate
|
|
228
229
|
else
|
229
230
|
0.1
|
230
231
|
end
|
231
|
-
|
232
232
|
end
|
233
233
|
|
234
234
|
scores[var] = [qs * qe * qc * ql * qt, size]
|
235
235
|
end
|
236
236
|
|
237
|
+
# DUH DON'T FORGET TO NUKE THE ZERO SCORES
|
238
|
+
scores.reject! { |_, s| s.first == 0 }
|
239
|
+
|
237
240
|
# XXX do something smarter here for secondary comparison
|
238
241
|
cmp ||= -> a, b { 0 }
|
239
242
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-negotiate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|