link-header-parser 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -4
- data/README.md +14 -26
- data/lib/link-header-parser.rb +8 -8
- data/lib/link_header_parser/link_header.rb +9 -8
- data/lib/link_header_parser/link_headers_collection.rb +6 -3
- data/lib/link_header_parser/version.rb +1 -1
- data/link-header-parser.gemspec +14 -14
- metadata +4 -5
- data/CONTRIBUTING.md +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9b629542a562a00905799bef5712836047d11c01164ebd1fa51f9d710741edb
|
4
|
+
data.tar.gz: 470f3e29a6da3ac405fbf16dddc99a394734d5743717ea53633e8845387dc7ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 779b4826009b1bd94856a17a2789c9cf54f440429543fde806d94ad47ba92c4fec80d981e5d8e60538f94f95ffa5a8e756bd4caff4a46ea6b5b1216ebd1edbfe
|
7
|
+
data.tar.gz: 489bec068d9c42302bc233339aa37d602ce189ad09e27d8fb2593eeb1cba0e84f4c1b0de8ecbac12b3902bbdc577640c38f5af437b04559c33a5fb930e886c3f
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 5.0.1 / 2023-12-08
|
4
|
+
|
5
|
+
- Refactor test suite (7a9a446)
|
6
|
+
- Miscellaneous RuboCop updates (512efa5, cc36a1e, 025d150, 36f9cc1)
|
7
|
+
- Update RuboCop configuration (376cf8e)
|
8
|
+
- Update development Ruby to 2.7.8 (5ca0757)
|
9
|
+
- Remove Bundler ecosystem config from Dependabot (8bcacdf)
|
10
|
+
- Update RSpec configuration (afef67d, 83583a1)
|
11
|
+
- Remove `code-scanning-rubocop` and `rspec-github` gems (154fd95)
|
12
|
+
|
3
13
|
## 5.0.0 / 2022-11-09
|
4
14
|
|
5
15
|
- **Breaking change:** Add `#to_ary`/`#to_a` method to `LinkHeadersCollection` (6a478ed)
|
6
|
-
|
16
|
+
- Note: marking this as a breaking change since it changes the existing behavior to return an `Array` of `Hash`es instead of an `Array` of `LinkHeader`s
|
7
17
|
- **Breaking change:** Update project Ruby version to 2.7.6 and minimum Ruby version to 2.7 (1e9df45)
|
8
18
|
- Improve documentation and privatize constants (8a68aa0)
|
9
19
|
- Remove Reek development dependency (423bc7a)
|
@@ -35,9 +45,9 @@
|
|
35
45
|
## 2.0.0 / 2020-05-21
|
36
46
|
|
37
47
|
- **Breaking changes:** Rewrite gem code (5351010)
|
38
|
-
|
39
|
-
|
40
|
-
|
48
|
+
- `LinkHeaderParser.parse` returns `LinkHeadersCollection`
|
49
|
+
- New classes: `LinkHeadersCollection`, `LinkHeader`, and `LinkHeaderParameter`
|
50
|
+
- Renamed collection's `by_relation_type` method to `group_by_relation_type`
|
41
51
|
- **Breaking change:** Update project Ruby version to 2.5.8 and minimum Ruby version to 2.5 (05b2e82)
|
42
52
|
- Update inline documentation and refactor `ParsedHeader` and `ParsedHeaderCollection` classes (31ec43e)
|
43
53
|
|
data/README.md
CHANGED
@@ -4,30 +4,22 @@
|
|
4
4
|
|
5
5
|
[![Gem](https://img.shields.io/gem/v/link-header-parser.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/link-header-parser)
|
6
6
|
[![Downloads](https://img.shields.io/gem/dt/link-header-parser.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/link-header-parser)
|
7
|
-
[![Build](https://img.shields.io/github/workflow/status/jgarber623/link-header-parser-ruby/
|
8
|
-
[![Maintainability](https://img.shields.io/codeclimate/maintainability/jgarber623/link-header-parser-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/jgarber623/link-header-parser-ruby)
|
9
|
-
[![Coverage](https://img.shields.io/codeclimate/c/jgarber623/link-header-parser-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/jgarber623/link-header-parser-ruby/code)
|
7
|
+
[![Build](https://img.shields.io/github/actions/workflow/status/jgarber623/link-header-parser-ruby/ci.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/jgarber623/link-header-parser-ruby/actions/workflows/ci.yml)
|
10
8
|
|
11
9
|
## Getting Started
|
12
10
|
|
13
|
-
Before installing and using link-header-parser-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed.
|
11
|
+
Before installing and using link-header-parser-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed. Using a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm) is recommended.
|
14
12
|
|
15
|
-
link-header-parser-ruby is developed using Ruby 2.7.
|
13
|
+
link-header-parser-ruby is developed using Ruby 2.7.8 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/jgarber623/link-header-parser-ruby/actions).
|
16
14
|
|
17
15
|
## Installation
|
18
16
|
|
19
|
-
|
17
|
+
Add link-header-parser-ruby to your project's `Gemfile` and run `bundle install`:
|
20
18
|
|
21
19
|
```ruby
|
22
|
-
source
|
20
|
+
source "https://rubygems.org"
|
23
21
|
|
24
|
-
gem
|
25
|
-
```
|
26
|
-
|
27
|
-
…and hop over to your command prompt and run…
|
28
|
-
|
29
|
-
```sh
|
30
|
-
$ bundle install
|
22
|
+
gem "link-header-parser"
|
31
23
|
```
|
32
24
|
|
33
25
|
## Usage
|
@@ -35,11 +27,11 @@ $ bundle install
|
|
35
27
|
With link-header-parser-ruby added to your project's `Gemfile` and installed, you may parse a URL's HTTP Link headers by doing:
|
36
28
|
|
37
29
|
```ruby
|
38
|
-
require
|
39
|
-
require
|
30
|
+
require "net/http"
|
31
|
+
require "link-header-parser"
|
40
32
|
|
41
|
-
url =
|
42
|
-
link_headers = Net::HTTP.get_response(URI.parse(url)).get_fields(
|
33
|
+
url = "https://sixtwothree.org"
|
34
|
+
link_headers = Net::HTTP.get_response(URI.parse(url)).get_fields("Link")
|
43
35
|
|
44
36
|
collection = LinkHeaderParser.parse(link_headers, base: url)
|
45
37
|
```
|
@@ -93,7 +85,7 @@ You may interact with one or more `LinkHeader`s in a `LinkHeadersCollection` usi
|
|
93
85
|
#### Link Target ([§ 3.1](https://tools.ietf.org/html/rfc8288#section-3.1))
|
94
86
|
|
95
87
|
```ruby
|
96
|
-
link_header = LinkHeaderParser.parse(
|
88
|
+
link_header = LinkHeaderParser.parse(%(</index.html>; rel="home"), base: "https://example.com/").first
|
97
89
|
|
98
90
|
link_header.target_string
|
99
91
|
#=> "/index.html"
|
@@ -107,7 +99,7 @@ The `target_string` method returns a string of the value between the opening and
|
|
107
99
|
#### Link Context ([§ 3.2](https://tools.ietf.org/html/rfc8288#section-3.2))
|
108
100
|
|
109
101
|
```ruby
|
110
|
-
link_header = LinkHeaderParser.parse(
|
102
|
+
link_header = LinkHeaderParser.parse(%(</chapters/1>; anchor="#copyright"; rel="license"), base: "https://example.com/").first
|
111
103
|
|
112
104
|
link_header.context_string
|
113
105
|
#=> "#copyright"
|
@@ -121,7 +113,7 @@ The `anchor` parameter's value may be a fragment identifier (e.g. `#foo`), a rel
|
|
121
113
|
#### Relation Type ([§ 3.3](https://tools.ietf.org/html/rfc8288#section-3.3))
|
122
114
|
|
123
115
|
```ruby
|
124
|
-
link_header = LinkHeaderParser.parse(
|
116
|
+
link_header = LinkHeaderParser.parse(%(</chapters/1>; rel="prev start"), base: "https://example.com/").first
|
125
117
|
|
126
118
|
link_header.relations_string
|
127
119
|
#=> "prev start"
|
@@ -133,7 +125,7 @@ link_header.relation_types
|
|
133
125
|
#### Link Parameters ([Appendix B.3](https://tools.ietf.org/html/rfc8288#appendix-B.3))
|
134
126
|
|
135
127
|
```ruby
|
136
|
-
link_header = LinkHeaderParser.parse(
|
128
|
+
link_header = LinkHeaderParser.parse(%(</posts.rss>; rel="alternate"; hreflang="en-US"; title="sixtwothree.org: Posts"; type="application/rss+xml"), base: "https://sixtwothree.org").first
|
137
129
|
|
138
130
|
link_header.link_parameters
|
139
131
|
#=> [#<LinkHeaderParser::LinkHeaderParameter name: "rel", value: "alternate">, #<LinkHeaderParser::LinkHeaderParameter name: "hreflang", value: "en-US">, #<LinkHeaderParser::LinkHeaderParameter name: "title", value: "sixtwothree.org: Posts">, #<LinkHeaderParser::LinkHeaderParameter name: "type", value: "application/rss+xml">]
|
@@ -141,10 +133,6 @@ link_header.link_parameters
|
|
141
133
|
|
142
134
|
Note that the `Array` returned by the `link_parameters` method may include multiple `LinkHeaderParameter`s with the same name depending on the provided Link header. Certain methods on `LinkHeader` will return values from the first occurrence of a parameter name (e.g. `link_header.relations_string`) in accordance with [RFC-8288](https://tools.ietf.org/html/rfc8288).
|
143
135
|
|
144
|
-
## Contributing
|
145
|
-
|
146
|
-
Interested in helping improve link-header-parser-ruby? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/jgarber623/link-header-parser-ruby/blob/main/CONTRIBUTING.md) for details.
|
147
|
-
|
148
136
|
## Acknowledgments
|
149
137
|
|
150
138
|
link-header-parser-ruby is written and maintained by [Jason Garber](https://sixtwothree.org).
|
data/lib/link-header-parser.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "forwardable"
|
4
4
|
|
5
|
-
require_relative
|
5
|
+
require_relative "link_header_parser/version"
|
6
6
|
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
7
|
+
require_relative "link_header_parser/link_header"
|
8
|
+
require_relative "link_header_parser/link_header_parameter"
|
9
|
+
require_relative "link_header_parser/link_headers_collection"
|
10
10
|
|
11
11
|
module LinkHeaderParser
|
12
12
|
# Parse an array of HTTP Link headers.
|
@@ -14,10 +14,10 @@ module LinkHeaderParser
|
|
14
14
|
# Convenience method for {LinkHeaderParser::LinkHeadersCollection#initialize}.
|
15
15
|
#
|
16
16
|
# @example
|
17
|
-
# require
|
17
|
+
# require "net/http"
|
18
18
|
#
|
19
|
-
# url =
|
20
|
-
# link_headers = Net::HTTP.get_response(URI.parse(url)).get_fields(
|
19
|
+
# url = "https://sixtwothree.org"
|
20
|
+
# link_headers = Net::HTTP.get_response(URI.parse(url)).get_fields("Link")
|
21
21
|
#
|
22
22
|
# LinkHeaderParser.parse(link_headers, base: url)
|
23
23
|
#
|
@@ -5,7 +5,7 @@ module LinkHeaderParser
|
|
5
5
|
FIELD_VALUE_REGEXP_PATTERN = /^\s*<\s*(?<target_string>[^>]+)\s*>\s*(?<parameters>;\s*.*)$/.freeze
|
6
6
|
private_constant :FIELD_VALUE_REGEXP_PATTERN
|
7
7
|
|
8
|
-
PARAMETERS_REGEXP_PATTERN = /(?<!;)\s*
|
8
|
+
PARAMETERS_REGEXP_PATTERN = /(?<!;)\s*[^;]+/.freeze
|
9
9
|
private_constant :PARAMETERS_REGEXP_PATTERN
|
10
10
|
|
11
11
|
# The +String+ value used to create this {LinkHeader}.
|
@@ -60,9 +60,9 @@ module LinkHeaderParser
|
|
60
60
|
#
|
61
61
|
# @return [Array<LinkHeaderParser::LinkHeaderParameter>]
|
62
62
|
def link_parameters
|
63
|
-
@link_parameters ||= field_value_match_data[:parameters]
|
64
|
-
|
65
|
-
|
63
|
+
@link_parameters ||= field_value_match_data[:parameters]
|
64
|
+
.scan(PARAMETERS_REGEXP_PATTERN)
|
65
|
+
.map { |parameter| LinkHeaderParameter.new(parameter.strip) }
|
66
66
|
end
|
67
67
|
|
68
68
|
# The +relations_string+ value returned as an +Array+.
|
@@ -133,10 +133,11 @@ module LinkHeaderParser
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def grouped_link_parameters
|
136
|
-
@grouped_link_parameters ||= link_parameters
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
@grouped_link_parameters ||= link_parameters
|
137
|
+
.map(&:to_a)
|
138
|
+
.group_by(&:shift)
|
139
|
+
.transform_keys(&:to_sym)
|
140
|
+
.transform_values(&:flatten)
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|
@@ -19,7 +19,9 @@ module LinkHeaderParser
|
|
19
19
|
# @param headers [Array<String, #to_str>]
|
20
20
|
# @param base [String, #to_str]
|
21
21
|
def initialize(*headers, base:)
|
22
|
+
# rubocop:disable Performance/ChainArrayAllocation
|
22
23
|
@headers = headers.to_ary.flatten.map(&:to_str)
|
24
|
+
# rubocop:enable Performance/ChainArrayAllocation
|
23
25
|
@base = base.to_str
|
24
26
|
|
25
27
|
push(*distinct_link_headers)
|
@@ -47,7 +49,7 @@ module LinkHeaderParser
|
|
47
49
|
#
|
48
50
|
# @return [Array<String>]
|
49
51
|
def relation_types
|
50
|
-
@relation_types ||= flat_map(&:relation_types).
|
52
|
+
@relation_types ||= Set.new(flat_map(&:relation_types)).to_a.sort
|
51
53
|
end
|
52
54
|
|
53
55
|
# Return an +Array+ representation of this {LinkHeadersCollection}.
|
@@ -66,8 +68,9 @@ module LinkHeaderParser
|
|
66
68
|
attr_reader :base
|
67
69
|
|
68
70
|
def distinct_link_headers
|
69
|
-
headers
|
70
|
-
|
71
|
+
headers
|
72
|
+
.flat_map { |header| header.split(/,(?=[\s|<])/) }
|
73
|
+
.map { |header| LinkHeader.new(header.strip, base: base) }
|
71
74
|
end
|
72
75
|
|
73
76
|
def members
|
data/link-header-parser.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "lib/link_header_parser/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.required_ruby_version =
|
6
|
+
spec.required_ruby_version = ">= 2.7", "< 4"
|
7
7
|
|
8
|
-
spec.name =
|
8
|
+
spec.name = "link-header-parser"
|
9
9
|
spec.version = LinkHeaderParser::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
10
|
+
spec.authors = ["Jason Garber"]
|
11
|
+
spec.email = ["jason@sixtwothree.org"]
|
12
12
|
|
13
|
-
spec.summary =
|
13
|
+
spec.summary = "Parse HTTP Link headers."
|
14
14
|
spec.description = spec.summary
|
15
|
-
spec.homepage =
|
16
|
-
spec.license =
|
15
|
+
spec.homepage = "https://github.com/jgarber623/link-header-parser-ruby"
|
16
|
+
spec.license = "MIT"
|
17
17
|
|
18
|
-
spec.files = Dir[
|
19
|
-
spec.files += %w[LICENSE CHANGELOG.md
|
18
|
+
spec.files = Dir["lib/**/*"].reject { |f| File.directory?(f) }
|
19
|
+
spec.files += %w[LICENSE CHANGELOG.md README.md]
|
20
20
|
spec.files += %w[link-header-parser.gemspec]
|
21
21
|
|
22
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.metadata = {
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
26
|
+
"changelog_uri" => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
|
27
|
+
"rubygems_mfa_required" => "true"
|
28
28
|
}
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link-header-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Garber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Parse HTTP Link headers.
|
14
14
|
email:
|
@@ -18,7 +18,6 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- CHANGELOG.md
|
21
|
-
- CONTRIBUTING.md
|
22
21
|
- LICENSE
|
23
22
|
- README.md
|
24
23
|
- lib/link-header-parser.rb
|
@@ -32,7 +31,7 @@ licenses:
|
|
32
31
|
- MIT
|
33
32
|
metadata:
|
34
33
|
bug_tracker_uri: https://github.com/jgarber623/link-header-parser-ruby/issues
|
35
|
-
changelog_uri: https://github.com/jgarber623/link-header-parser-ruby/blob/v5.0.
|
34
|
+
changelog_uri: https://github.com/jgarber623/link-header-parser-ruby/blob/v5.0.1/CHANGELOG.md
|
36
35
|
rubygems_mfa_required: 'true'
|
37
36
|
post_install_message:
|
38
37
|
rdoc_options: []
|
@@ -52,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: '0'
|
54
53
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
54
|
+
rubygems_version: 3.1.6
|
56
55
|
signing_key:
|
57
56
|
specification_version: 4
|
58
57
|
summary: Parse HTTP Link headers.
|
data/CONTRIBUTING.md
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# Contributing to link-header-parser-ruby
|
2
|
-
|
3
|
-
There are a couple ways you can help improve link-header-parser-ruby:
|
4
|
-
|
5
|
-
1. Fix an existing [issue][issues] and submit a [pull request][pulls].
|
6
|
-
1. Review open [pull requests][pulls].
|
7
|
-
1. Report a new [issue][issues]. _Only do this after you've made sure the behavior or problem you're observing isn't already documented in an open issue._
|
8
|
-
|
9
|
-
## Getting Started
|
10
|
-
|
11
|
-
link-header-parser-ruby is developed using Ruby 2.7.6 and is additionally tested against Ruby 3.0 and 3.1 using [GitHub Actions](https://github.com/jgarber623/link-header-parser-ruby/actions).
|
12
|
-
|
13
|
-
Before making changes to link-header-parser-ruby, you'll want to install Ruby 2.7.6. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.7.6 using your method of choice, install the project's gems by running:
|
14
|
-
|
15
|
-
```sh
|
16
|
-
bundle install
|
17
|
-
```
|
18
|
-
|
19
|
-
## Making Changes
|
20
|
-
|
21
|
-
1. Fork and clone the project's repo.
|
22
|
-
1. Install development dependencies as outlined above.
|
23
|
-
1. Create a feature branch for the code changes you're looking to make: `git checkout -b my-new-feature`.
|
24
|
-
1. _Write some code!_
|
25
|
-
1. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `bundle exec rspec`.
|
26
|
-
1. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`. _(See [this excellent article](https://chris.beams.io/posts/git-commit/) for tips on writing useful Git commit messages.)_
|
27
|
-
1. Push the branch to your fork: `git push -u origin my-new-feature`.
|
28
|
-
1. Create a new [pull request][pulls] and we'll review your changes.
|
29
|
-
|
30
|
-
## Code Style
|
31
|
-
|
32
|
-
Code formatting conventions are defined in the `.editorconfig` file which uses the [EditorConfig](http://editorconfig.org) syntax. There are [plugins for a variety of editors](http://editorconfig.org/#download) that utilize the settings in the `.editorconfig` file. We recommended you install the EditorConfig plugin for your editor of choice.
|
33
|
-
|
34
|
-
Your bug fix or feature addition won't be rejected if it runs afoul of any (or all) of these guidelines, but following the guidelines will definitely make everyone's lives a little easier.
|
35
|
-
|
36
|
-
[issues]: https://github.com/jgarber623/link-header-parser-ruby/issues
|
37
|
-
[pulls]: https://github.com/jgarber623/link-header-parser-ruby/pulls
|