linkheaders-processor 0.1.20 → 0.1.21

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: d24a4ec87d13cc6f5fb9ba02ffa92f898782ee520ce4e4df19c424fc1bf52133
4
- data.tar.gz: 5f95faf4fc44d7334df1cd2311c0d59aa3cd079fa0d5de92ffa793b1b280e69f
3
+ metadata.gz: 88db7265719e8b2f1d6fa9f804d6970dc411f6ff609cdff6fbf21f9e904d76d8
4
+ data.tar.gz: b504685f471206e45bae949bc3f423c2ed9e9aedca7c0d27784c5ca6d6a78e02
5
5
  SHA512:
6
- metadata.gz: 95e6929649e7f9e04b91de7e01f261204846325d65d54059ea4219b634723b29b64138bcfaf487959be2588a66dbf6a29d73dc836123331fc7e7f5b0335f32fc
7
- data.tar.gz: dce8353665fa1110dbeacc2efe4e98614425e17ac431a936fc3b96cbf7b0af1d8346c25997adea42753b4efa6de341a2a2d9eb74bb774a3a564c9b50093c6a21
6
+ metadata.gz: a1973c63103587b077879d1d53fa50cc5f9b1102a3dd8db2e56d792ceaa0d60addcb8a3edeb50069fa3263c2f4820e09cdd9714579c4d0b119ab2cbbe5e44122
7
+ data.tar.gz: ce8c65a0e657430caca6abff60c435aa79bc659f6623017ddb9d7e90d2988c7f51650ca7f89df58b2c5db2a1b904c8137da7c66c1557d08f80208304cef6ba8d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- linkheaders-processor (0.1.20)
4
+ linkheaders-processor (0.1.21)
5
5
  json (~> 2.0)
6
6
  json-ld (~> 3.2)
7
7
  json-ld-preloaded (~> 3.2)
@@ -134,7 +134,7 @@ GEM
134
134
  parser (>= 3.1.1.0)
135
135
  ruby-progressbar (1.11.0)
136
136
  ruby2_keywords (0.0.5)
137
- securerandom (0.1.1)
137
+ securerandom (0.2.2)
138
138
  unf (0.1.4)
139
139
  unf_ext
140
140
  unf_ext (0.0.8.2)
@@ -3,6 +3,6 @@
3
3
 
4
4
  module LinkHeaders
5
5
  class Processor
6
- VERSION = "0.1.20"
6
+ VERSION = "0.1.21"
7
7
  end
8
8
  end
@@ -96,28 +96,33 @@ module LinkHeaders
96
96
  def split_http_link_headers_and_process(parts)
97
97
  newlinks = Array.new
98
98
  parts.each do |part, _index|
99
- # warn "link is: #{part}"
100
-
101
- section = part.split(';') # ["<https://example.one.com>", "rel='preconnect'"]
102
- warn section
103
- next unless section[0]
104
-
105
- href = section[0][/<(.*)>/, 1]
106
- next unless href # this is mandatory!
107
-
108
- next unless section[1]
99
+ warn "link is: #{part}" # <https://s11.no/2022/a2a-fair-metrics/70-rda-r1-01m-t2-type-charset/test-apple-data.csv>;rel="item";type="text/csv;charset=UTF-8"
100
+
101
+ # this is crazy hard, because we can't rely on quotes!
102
+ part = part + ";"
103
+ href = part[/<([^\]]+)>;/, 1]
104
+ next unless href
105
+ part = part.gsub(/<([^\]]+)>\s?;\s?/, "") # now only ;rel="item";type="text/csv;charset=UTF-8"; pro=gram
106
+ pieces = part.scan(/(\S+?\s?=\s?"[^"]+?"\s?);?/).flatten # ["rel=\"item\"", "type=\"text/csv;charset=UTF-8\""] and the non-quoted stuff is ignored
107
+ pieces.each do |p|
108
+ part = part.gsub(p, "") # now just ";;prog=gram;"
109
+ end
110
+ rest = part.split(";") # ["", "", "prog=gram"]
109
111
 
110
112
  sections = {}
111
- section[1..].each do |s| # can be more than one link property "rel='preconnect'"
113
+ pieces.concat(rest).each do |s| # can be more than one link property "rel='preconnect'"
112
114
  s.strip!
113
- unless m = s.match(%r{(\w+?)="?([\w:\d.,\#\-+/\s]+)"?})
115
+ unless m = s.match(%r{(\w+?)\s?=\s?"?([\w\;\:\d\.\,\=\#\-\+\/\s]+)"?})
116
+ warn " NO PATTERN MATCH ON #{s}"
114
117
  next
115
118
  end # can be rel="cite-as describedby" --> two relations in one! or "linkset+json"
116
119
 
117
120
  relation = m[1] # rel"
118
121
  value = m[2] # "preconnect"
122
+ warn "section relation #{relation} value #{value}"
119
123
  sections[relation] = value # value could hold multiple relation types sections[:rel] = "preconnect"
120
124
  end
125
+
121
126
  next unless sections['rel'] # the relation is required!
122
127
 
123
128
  anchor = sections['anchor'] || default_anchor
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linkheaders-processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Wilkinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-28 00:00:00.000000000 Z
11
+ date: 2023-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec