rack-link_headers 2.2.2 → 2.3.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 +13 -6
- data/lib/rack-link_headers.rb +2 -0
- data/lib/rack/link_headers/helper.rb +14 -8
- data/lib/rack/link_headers/version.rb +4 -2
- data/rack-link-headers.gemspec +19 -19
- data/test/helper_test.rb +20 -26
- metadata +9 -44
- 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: 923b708b4765a8eb504d6d4337de4bcc21abd40a0509c0c7851e649b23777fe2
|
4
|
+
data.tar.gz: c4634d4822bf971fe5ed4c9af90e9756942b3d47c05024444e94c7d68ce951bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0deb2f9e6382622c350932f7f42cecec4a7ecba8b82182aac914fffe1d74538b99d25195932eba609ed8e39389ff1fc23baf57970a9224253bc82d6675b1dff
|
7
|
+
data.tar.gz: 5e1ee525a5f8a6595c152bee35b4b6ae4be63e970a393e29d66b005bf7fe9c27bd3287c310c220e60b53d748656b965061d41e5c26f627a4497a530133b3e118
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Rack::LinkHeaders
|
1
|
+
# Rack::LinkHeaders
|
2
|
+
|
3
|
+
[![Build Status](https://github.com/jgraichen/rack-link_headers/workflows/Build/badge.svg?event=push)](https://github.com/jgraichen/rack-link_headers/actions?query=workflow%3ABuild)
|
2
4
|
|
3
5
|
Easy Link header management for rack responses.
|
4
6
|
|
@@ -19,8 +21,8 @@ Or install it yourself as:
|
|
19
21
|
## Usage
|
20
22
|
|
21
23
|
```ruby
|
22
|
-
response.link "http://abc.de/", :
|
23
|
-
response.link "http://test.host/feed.xml", :
|
24
|
+
response.link "http://abc.de/", rel: :search
|
25
|
+
response.link "http://test.host/feed.xml", rel: :rss, type: "application/rss+xml"
|
24
26
|
```
|
25
27
|
```
|
26
28
|
response.headers["Link"]
|
@@ -31,11 +33,16 @@ Manual set Link header will be overridden. All links can be
|
|
31
33
|
accessed via `links`:
|
32
34
|
|
33
35
|
```ruby
|
34
|
-
response.link "http://abc.de/", :
|
35
|
-
response.link "http://test.host/feed.xml", :
|
36
|
+
response.link "http://abc.de/", rel: :search
|
37
|
+
response.link "http://test.host/feed.xml", rel: :rss, type: "application/rss+xml"
|
36
38
|
|
37
39
|
response.links
|
38
|
-
# => [
|
40
|
+
# => [
|
41
|
+
# {:url=>"http://abc.de/",
|
42
|
+
# :params=>{:ref=>:search}},
|
43
|
+
# {:url=>"http://test.host/feed.xml",
|
44
|
+
# :params=>{:rel=>:rss, :type=>"application/rss+xml"}}
|
45
|
+
# ]
|
39
46
|
```
|
40
47
|
|
41
48
|
## Contributing
|
data/lib/rack-link_headers.rb
CHANGED
@@ -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
|
data/rack-link-headers.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
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
|
-
gem.license = 'MIT'
|
16
|
-
|
17
|
-
gem.files = `git ls-files`.split($/)
|
18
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
-
gem.require_paths = ["lib"]
|
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'
|
21
16
|
|
22
|
-
|
17
|
+
spec.files = Dir['**/*'].grep(%r{^(
|
18
|
+
(bin|lib|test|spec|features)/|
|
19
|
+
(.*\.gemspec|.*LICENSE.*|.*README.*|.*CHANGELOG.*)
|
20
|
+
)}x)
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ['lib']
|
23
24
|
|
24
|
-
|
25
|
-
gem.add_development_dependency 'rake'
|
25
|
+
spec.add_runtime_dependency 'rack'
|
26
26
|
end
|
data/test/helper_test.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
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
14
|
class HelperTest < MiniTest::Unit::TestCase
|
@@ -17,45 +17,39 @@ class HelperTest < MiniTest::Unit::TestCase
|
|
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"', @response.headers['Link']
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_links
|
33
|
-
@response.link
|
34
|
-
@response.link
|
33
|
+
@response.link 'http://google.com/path?query=5#frag', rel: :search
|
34
|
+
@response.link 'http://test.host/feed.rss', rel: :rss, type: 'application/rss+xml'
|
35
35
|
|
36
|
-
assert_equal @response.links, [{:
|
37
|
-
|
36
|
+
assert_equal @response.links, [{url: 'http://google.com/path?query=5#frag', params: {rel: :search}},
|
37
|
+
{url: 'http://test.host/feed.rss', params: {rel: :rss, type: 'application/rss+xml'}}]
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_overrides_manual_headers
|
41
|
-
@response.headers[
|
41
|
+
@response.headers['Link'] = 'http://abc.de/'
|
42
42
|
|
43
|
-
assert_equal
|
43
|
+
assert_equal 'http://abc.de/', @response.headers['Link']
|
44
44
|
|
45
|
-
@response.link
|
45
|
+
@response.link 'http://google.com/path?query=5#frag', rel: :search
|
46
46
|
|
47
|
-
assert_equal
|
47
|
+
assert_equal '<http://google.com/path?query=5#frag>; rel="search"', @response.headers['Link']
|
48
48
|
end
|
49
49
|
|
50
|
-
if
|
50
|
+
if ACTIONPACK
|
51
51
|
def test_dyn_inject_action_dispatch_response
|
52
52
|
assert ActionDispatch::Response.new.respond_to? :link
|
53
53
|
end
|
54
54
|
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
55
|
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.3.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: 2020-12-13 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
|
@@ -82,17 +48,16 @@ require_paths:
|
|
82
48
|
- lib
|
83
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
50
|
requirements:
|
85
|
-
- -
|
51
|
+
- - ">="
|
86
52
|
- !ruby/object:Gem::Version
|
87
53
|
version: '0'
|
88
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
55
|
requirements:
|
90
|
-
- -
|
56
|
+
- - ">="
|
91
57
|
- !ruby/object:Gem::Version
|
92
58
|
version: '0'
|
93
59
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.0.3
|
60
|
+
rubygems_version: 3.1.2
|
96
61
|
signing_key:
|
97
62
|
specification_version: 4
|
98
63
|
summary: Easy Link header management for rack responses.
|
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