rack-link_headers 2.2.2 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +26 -11
- data/lib/rack/link_headers/helper.rb +14 -8
- data/lib/rack/link_headers/version.rb +5 -3
- data/lib/rack-link_headers.rb +2 -0
- data/rack-link-headers.gemspec +21 -18
- data/test/helper_test.rb +24 -27
- metadata +13 -48
- data/.gitignore +0 -23
- data/.travis.yml +0 -10
- data/Gemfile +0 -8
- data/Rakefile +0 -10
- data/gemfiles/Gemfile.rails-3-2 +0 -6
- data/gemfiles/Gemfile.rails-head +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 671eeb60f4abb81feaee2bbe86a0ab04bf2608d47b27aa6c0bc2560d8171c327
|
4
|
+
data.tar.gz: ad43357571a86ed6732079cad2785f62b18c6f9f970f72c5b73332c8f9114d92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 336743659f0eb6c603d2ab6da5f9d27f9057eb1f82ce2180549954b5339ada7836630bbfe349178a5fcf92aa65cbc90f00798f25bcc7383b86069b56b9e75cfd
|
7
|
+
data.tar.gz: edb4cea104f72b958f73dad53405cf3049572a0eb518e7d070f1fe78f5f49326ac77a0a22c5c9a4b41ba3999472fcd1f617fab86d86862b447349d57a376f7e6
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# Rack::LinkHeaders
|
1
|
+
# Rack::LinkHeaders
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/rack-link_headers?logo=ruby)](https://rubygems.org/gems/rack-link_headers)
|
4
|
+
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jgraichen/rack-link_headers/test.yml?logo=github)](https://github.com/jgraichen/rack-link_headers/actions/workflows/test.yml)
|
2
5
|
|
3
6
|
Easy Link header management for rack responses.
|
4
7
|
|
@@ -6,23 +9,30 @@ Easy Link header management for rack responses.
|
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
8
11
|
|
9
|
-
|
12
|
+
```ruby
|
13
|
+
gem 'rack-link_headers', '~> 2.4'
|
14
|
+
```
|
10
15
|
|
11
16
|
And then execute:
|
12
17
|
|
13
|
-
|
18
|
+
```console
|
19
|
+
bundle
|
20
|
+
```
|
14
21
|
|
15
22
|
Or install it yourself as:
|
16
23
|
|
17
|
-
|
24
|
+
```console
|
25
|
+
gem install rack-link_headers
|
26
|
+
```
|
18
27
|
|
19
28
|
## Usage
|
20
29
|
|
21
30
|
```ruby
|
22
|
-
response.link "http://abc.de/", :
|
23
|
-
response.link "http://test.host/feed.xml", :
|
24
|
-
```
|
31
|
+
response.link "http://abc.de/", rel: :search
|
32
|
+
response.link "http://test.host/feed.xml", rel: :rss, type: "application/rss+xml"
|
25
33
|
```
|
34
|
+
|
35
|
+
```ruby
|
26
36
|
response.headers["Link"]
|
27
37
|
# => <http://abc.de/>; rel="rel", <http://test.host/feed.xml>; rel="rss"; type="application/rss+xml"
|
28
38
|
```
|
@@ -31,11 +41,16 @@ Manual set Link header will be overridden. All links can be
|
|
31
41
|
accessed via `links`:
|
32
42
|
|
33
43
|
```ruby
|
34
|
-
response.link "http://abc.de/", :
|
35
|
-
response.link "http://test.host/feed.xml", :
|
44
|
+
response.link "http://abc.de/", rel: :search
|
45
|
+
response.link "http://test.host/feed.xml", rel: :rss, type: "application/rss+xml"
|
36
46
|
|
37
47
|
response.links
|
38
|
-
# => [
|
48
|
+
# => [
|
49
|
+
# {:url=>"http://abc.de/",
|
50
|
+
# :params=>{:ref=>:search}},
|
51
|
+
# {:url=>"http://test.host/feed.xml",
|
52
|
+
# :params=>{:rel=>:rss, :type=>"application/rss+xml"}}
|
53
|
+
# ]
|
39
54
|
```
|
40
55
|
|
41
56
|
## Contributing
|
@@ -52,4 +67,4 @@ response.links
|
|
52
67
|
|
53
68
|
[MIT License](http://www.opensource.org/licenses/mit-license.php)
|
54
69
|
|
55
|
-
Copyright
|
70
|
+
Copyright © 2023, Jan Graichen
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rack'
|
2
4
|
|
3
5
|
module Rack
|
4
6
|
module LinkHeaders
|
@@ -14,9 +16,9 @@ module Rack
|
|
14
16
|
# sanitize anything. Manual added Link headers will be
|
15
17
|
# overridden.
|
16
18
|
def link(url, params = {})
|
17
|
-
links << {:
|
19
|
+
links << {url: url.to_s, params: params}
|
18
20
|
|
19
|
-
self[
|
21
|
+
self['Link'] = links.to_a.map do |link|
|
20
22
|
"<#{link[:url]}>" + link[:params].keys.sort.map do |k|
|
21
23
|
"; #{k}=\"#{link[:params][k]}\""
|
22
24
|
end.join
|
@@ -24,15 +26,19 @@ module Rack
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def links
|
27
|
-
@
|
29
|
+
@links ||= []
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
Rack::Response.
|
35
|
-
Rack::Response::Helpers.
|
36
|
+
Rack::Response.include Rack::LinkHeaders::Helper
|
37
|
+
Rack::Response::Helpers.include Rack::LinkHeaders::Helper
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
+
if defined?(ActionDispatch::Response)
|
40
|
+
ActionDispatch::Response.include Rack::LinkHeaders::Helper
|
41
|
+
end
|
42
|
+
if defined?(ActionController::TestResponse)
|
43
|
+
ActionController::TestResponse.include Rack::LinkHeaders::Helper
|
44
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rack
|
2
4
|
module LinkHeaders
|
3
5
|
module VERSION
|
4
6
|
MAJOR = 2
|
5
|
-
MINOR =
|
6
|
-
PATCH =
|
7
|
+
MINOR = 4
|
8
|
+
PATCH = 0
|
7
9
|
STAGE = nil
|
8
10
|
|
9
11
|
def self.to_s
|
10
|
-
[MAJOR, MINOR, PATCH, STAGE].
|
12
|
+
[MAJOR, MINOR, PATCH, STAGE].compact.join '.'
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/rack-link_headers.rb
CHANGED
data/rack-link-headers.gemspec
CHANGED
@@ -1,26 +1,29 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
|
5
6
|
require 'rack/link_headers/version'
|
6
7
|
|
7
|
-
Gem::Specification.new do |
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'rack-link_headers'
|
10
|
+
spec.version = Rack::LinkHeaders::VERSION
|
11
|
+
spec.authors = ['Jan Graichen']
|
12
|
+
spec.email = ['jgraichen@altimos.de']
|
13
|
+
spec.summary = 'Easy Link header management for rack responses.'
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 2.7.0'
|
18
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
spec.files = Dir['**/*'].grep(%r{^(
|
21
|
+
(bin|lib|test|spec|features)/|
|
22
|
+
(.*\.gemspec|.*LICENSE.*|.*README.*|.*CHANGELOG.*)
|
23
|
+
)}x)
|
21
24
|
|
22
|
-
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
23
27
|
|
24
|
-
|
25
|
-
gem.add_development_dependency 'rake'
|
28
|
+
spec.add_runtime_dependency 'rack'
|
26
29
|
end
|
data/test/helper_test.rb
CHANGED
@@ -1,61 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
|
3
|
-
|
5
|
+
ACTIONPACK = !ENV['ACTIONPACK'].to_s.empty?
|
6
|
+
|
7
|
+
if ACTIONPACK
|
8
|
+
# For testing ActionDispatch::Response
|
4
9
|
require 'action_dispatch'
|
5
10
|
end
|
6
|
-
if ENV["GEM"].to_s.include?('ac')
|
7
|
-
require 'action_controller'
|
8
|
-
require 'action_controller/test_case'
|
9
|
-
end
|
10
11
|
|
11
|
-
require 'rack/response'
|
12
12
|
require 'rack-link_headers'
|
13
13
|
|
14
|
-
class HelperTest <
|
14
|
+
class HelperTest < Minitest::Test
|
15
15
|
def setup
|
16
16
|
@response = Rack::Response.new
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_link_writes_header
|
20
|
-
@response.link
|
20
|
+
@response.link 'http://google.com/path?query=5#frag', rel: :search
|
21
21
|
|
22
|
-
assert_equal
|
22
|
+
assert_equal '<http://google.com/path?query=5#frag>; rel="search"', @response.headers['Link']
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_multiple_link_writes_header
|
26
|
-
@response.link
|
27
|
-
@response.link
|
26
|
+
@response.link 'http://google.com/path?query=5#frag', rel: :search
|
27
|
+
@response.link 'http://test.host/feed.rss', rel: :rss, type: 'application/rss+xml'
|
28
28
|
|
29
|
-
assert_equal
|
29
|
+
assert_equal '<http://google.com/path?query=5#frag>; rel="search", <http://test.host/feed.rss>; rel="rss"; type="application/rss+xml"',
|
30
|
+
@response.headers['Link']
|
30
31
|
end
|
31
32
|
|
32
33
|
def test_links
|
33
|
-
@response.link
|
34
|
-
@response.link
|
34
|
+
@response.link 'http://google.com/path?query=5#frag', rel: :search
|
35
|
+
@response.link 'http://test.host/feed.rss', rel: :rss, type: 'application/rss+xml'
|
35
36
|
|
36
|
-
assert_equal @response.links, [
|
37
|
-
{:
|
37
|
+
assert_equal @response.links, [
|
38
|
+
{url: 'http://google.com/path?query=5#frag', params: {rel: :search}},
|
39
|
+
{url: 'http://test.host/feed.rss', params: {rel: :rss, type: 'application/rss+xml'}},
|
40
|
+
]
|
38
41
|
end
|
39
42
|
|
40
43
|
def test_overrides_manual_headers
|
41
|
-
@response.headers[
|
44
|
+
@response.headers['Link'] = 'http://abc.de/'
|
42
45
|
|
43
|
-
assert_equal
|
46
|
+
assert_equal 'http://abc.de/', @response.headers['Link']
|
44
47
|
|
45
|
-
@response.link
|
48
|
+
@response.link 'http://google.com/path?query=5#frag', rel: :search
|
46
49
|
|
47
|
-
assert_equal
|
50
|
+
assert_equal '<http://google.com/path?query=5#frag>; rel="search"', @response.headers['Link']
|
48
51
|
end
|
49
52
|
|
50
|
-
if
|
53
|
+
if ACTIONPACK
|
51
54
|
def test_dyn_inject_action_dispatch_response
|
52
55
|
assert ActionDispatch::Response.new.respond_to? :link
|
53
56
|
end
|
54
57
|
end
|
55
|
-
|
56
|
-
if ENV["GEM"].to_s.include?('ac')
|
57
|
-
def test_dyn_inject_action_controller_test_response
|
58
|
-
assert ActionController::TestResponse.new.respond_to? :link
|
59
|
-
end
|
60
|
-
end
|
61
58
|
end
|
metadata
CHANGED
@@ -1,72 +1,38 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-link_headers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
description: Easy Link header management for rack responses.
|
27
|
+
description:
|
56
28
|
email:
|
57
|
-
-
|
29
|
+
- jgraichen@altimos.de
|
58
30
|
executables: []
|
59
31
|
extensions: []
|
60
32
|
extra_rdoc_files: []
|
61
33
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .travis.yml
|
64
|
-
- Gemfile
|
65
34
|
- LICENSE.txt
|
66
35
|
- README.md
|
67
|
-
- Rakefile
|
68
|
-
- gemfiles/Gemfile.rails-3-2
|
69
|
-
- gemfiles/Gemfile.rails-head
|
70
36
|
- lib/rack-link_headers.rb
|
71
37
|
- lib/rack/link_headers/helper.rb
|
72
38
|
- lib/rack/link_headers/version.rb
|
@@ -75,26 +41,25 @@ files:
|
|
75
41
|
homepage: ''
|
76
42
|
licenses:
|
77
43
|
- MIT
|
78
|
-
metadata:
|
44
|
+
metadata:
|
45
|
+
rubygems_mfa_required: 'true'
|
79
46
|
post_install_message:
|
80
47
|
rdoc_options: []
|
81
48
|
require_paths:
|
82
49
|
- lib
|
83
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
51
|
requirements:
|
85
|
-
- -
|
52
|
+
- - ">="
|
86
53
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
54
|
+
version: 2.7.0
|
88
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
56
|
requirements:
|
90
|
-
- -
|
57
|
+
- - ">="
|
91
58
|
- !ruby/object:Gem::Version
|
92
59
|
version: '0'
|
93
60
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.0.3
|
61
|
+
rubygems_version: 3.4.10
|
96
62
|
signing_key:
|
97
63
|
specification_version: 4
|
98
64
|
summary: Easy Link header management for rack responses.
|
99
|
-
test_files:
|
100
|
-
- test/helper_test.rb
|
65
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
*.iml
|
4
|
-
.bundle
|
5
|
-
.config
|
6
|
-
.yardoc
|
7
|
-
.rbx
|
8
|
-
.idea
|
9
|
-
.rvmrc
|
10
|
-
.rbx
|
11
|
-
Gemfile.lock
|
12
|
-
InstalledFiles
|
13
|
-
_yardoc
|
14
|
-
coverage
|
15
|
-
doc/
|
16
|
-
lib/bundler/man
|
17
|
-
pkg
|
18
|
-
rdoc
|
19
|
-
spec/reports
|
20
|
-
test/tmp
|
21
|
-
test/version_tmp
|
22
|
-
tmp
|
23
|
-
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/gemfiles/Gemfile.rails-3-2
DELETED