rails_http_preload 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +75 -74
- data/README.md +1 -1
- data/lib/rails_http_preload/middleware.rb +16 -11
- data/lib/rails_http_preload/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61c3fa6d2a963768a57379057000200b6cbd12dcce2dd7b1f196025ddd293ac9
|
4
|
+
data.tar.gz: 6e02d5a4bef38c2e0b10767e0a0b9e3ca497e64ace257e2d21181b458156746f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c9a33394ef06842c7e75bca1a91f5aa3c043589acae80ebfd246d5e4d4b0417b704bce8af2d5178159966db42f1302e4460f3cfbc12223e0043f454b60af9c7
|
7
|
+
data.tar.gz: b34234412e0b00c63ff2c33ef838fb0b7b571200f80650e592a8dbebcc7d4e84aba16db0c90795f5b5b868d5c0152b59e8ae23361be17cf5471a19da01f389fd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2022-05-29
|
4
|
+
|
5
|
+
- Removed unnecessary require statement
|
6
|
+
|
7
|
+
## [0.2.0] - 2022-05-29
|
8
|
+
|
9
|
+
- Bugfix: blank asset hosts should not add a blank link header
|
10
|
+
- Bugfix: don't overwrite existing link headers in responses
|
11
|
+
|
3
12
|
## [0.1.0] - 2022-11-21
|
4
13
|
|
5
14
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_http_preload (0.
|
4
|
+
rails_http_preload (0.3.0)
|
5
5
|
actionpack
|
6
6
|
actionview
|
7
7
|
rails
|
@@ -9,86 +9,86 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actioncable (7.0.
|
13
|
-
actionpack (= 7.0.
|
14
|
-
activesupport (= 7.0.
|
12
|
+
actioncable (7.0.5)
|
13
|
+
actionpack (= 7.0.5)
|
14
|
+
activesupport (= 7.0.5)
|
15
15
|
nio4r (~> 2.0)
|
16
16
|
websocket-driver (>= 0.6.1)
|
17
|
-
actionmailbox (7.0.
|
18
|
-
actionpack (= 7.0.
|
19
|
-
activejob (= 7.0.
|
20
|
-
activerecord (= 7.0.
|
21
|
-
activestorage (= 7.0.
|
22
|
-
activesupport (= 7.0.
|
17
|
+
actionmailbox (7.0.5)
|
18
|
+
actionpack (= 7.0.5)
|
19
|
+
activejob (= 7.0.5)
|
20
|
+
activerecord (= 7.0.5)
|
21
|
+
activestorage (= 7.0.5)
|
22
|
+
activesupport (= 7.0.5)
|
23
23
|
mail (>= 2.7.1)
|
24
24
|
net-imap
|
25
25
|
net-pop
|
26
26
|
net-smtp
|
27
|
-
actionmailer (7.0.
|
28
|
-
actionpack (= 7.0.
|
29
|
-
actionview (= 7.0.
|
30
|
-
activejob (= 7.0.
|
31
|
-
activesupport (= 7.0.
|
27
|
+
actionmailer (7.0.5)
|
28
|
+
actionpack (= 7.0.5)
|
29
|
+
actionview (= 7.0.5)
|
30
|
+
activejob (= 7.0.5)
|
31
|
+
activesupport (= 7.0.5)
|
32
32
|
mail (~> 2.5, >= 2.5.4)
|
33
33
|
net-imap
|
34
34
|
net-pop
|
35
35
|
net-smtp
|
36
36
|
rails-dom-testing (~> 2.0)
|
37
|
-
actionpack (7.0.
|
38
|
-
actionview (= 7.0.
|
39
|
-
activesupport (= 7.0.
|
40
|
-
rack (~> 2.0, >= 2.2.
|
37
|
+
actionpack (7.0.5)
|
38
|
+
actionview (= 7.0.5)
|
39
|
+
activesupport (= 7.0.5)
|
40
|
+
rack (~> 2.0, >= 2.2.4)
|
41
41
|
rack-test (>= 0.6.3)
|
42
42
|
rails-dom-testing (~> 2.0)
|
43
43
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
44
|
-
actiontext (7.0.
|
45
|
-
actionpack (= 7.0.
|
46
|
-
activerecord (= 7.0.
|
47
|
-
activestorage (= 7.0.
|
48
|
-
activesupport (= 7.0.
|
44
|
+
actiontext (7.0.5)
|
45
|
+
actionpack (= 7.0.5)
|
46
|
+
activerecord (= 7.0.5)
|
47
|
+
activestorage (= 7.0.5)
|
48
|
+
activesupport (= 7.0.5)
|
49
49
|
globalid (>= 0.6.0)
|
50
50
|
nokogiri (>= 1.8.5)
|
51
|
-
actionview (7.0.
|
52
|
-
activesupport (= 7.0.
|
51
|
+
actionview (7.0.5)
|
52
|
+
activesupport (= 7.0.5)
|
53
53
|
builder (~> 3.1)
|
54
54
|
erubi (~> 1.4)
|
55
55
|
rails-dom-testing (~> 2.0)
|
56
56
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
57
|
-
activejob (7.0.
|
58
|
-
activesupport (= 7.0.
|
57
|
+
activejob (7.0.5)
|
58
|
+
activesupport (= 7.0.5)
|
59
59
|
globalid (>= 0.3.6)
|
60
|
-
activemodel (7.0.
|
61
|
-
activesupport (= 7.0.
|
62
|
-
activerecord (7.0.
|
63
|
-
activemodel (= 7.0.
|
64
|
-
activesupport (= 7.0.
|
65
|
-
activestorage (7.0.
|
66
|
-
actionpack (= 7.0.
|
67
|
-
activejob (= 7.0.
|
68
|
-
activerecord (= 7.0.
|
69
|
-
activesupport (= 7.0.
|
60
|
+
activemodel (7.0.5)
|
61
|
+
activesupport (= 7.0.5)
|
62
|
+
activerecord (7.0.5)
|
63
|
+
activemodel (= 7.0.5)
|
64
|
+
activesupport (= 7.0.5)
|
65
|
+
activestorage (7.0.5)
|
66
|
+
actionpack (= 7.0.5)
|
67
|
+
activejob (= 7.0.5)
|
68
|
+
activerecord (= 7.0.5)
|
69
|
+
activesupport (= 7.0.5)
|
70
70
|
marcel (~> 1.0)
|
71
71
|
mini_mime (>= 1.1.0)
|
72
|
-
activesupport (7.0.
|
72
|
+
activesupport (7.0.5)
|
73
73
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
74
74
|
i18n (>= 1.6, < 2)
|
75
75
|
minitest (>= 5.1)
|
76
76
|
tzinfo (~> 2.0)
|
77
77
|
ast (2.4.2)
|
78
78
|
builder (3.2.4)
|
79
|
-
concurrent-ruby (1.
|
79
|
+
concurrent-ruby (1.2.2)
|
80
80
|
crass (1.0.6)
|
81
81
|
date (3.3.3)
|
82
82
|
erubi (1.12.0)
|
83
|
-
globalid (1.
|
83
|
+
globalid (1.1.0)
|
84
84
|
activesupport (>= 5.0)
|
85
|
-
i18n (1.
|
85
|
+
i18n (1.13.0)
|
86
86
|
concurrent-ruby (~> 1.0)
|
87
87
|
json (2.6.3)
|
88
|
-
loofah (2.
|
88
|
+
loofah (2.21.3)
|
89
89
|
crass (~> 1.0.2)
|
90
|
-
nokogiri (>= 1.
|
91
|
-
mail (2.8.
|
90
|
+
nokogiri (>= 1.12.0)
|
91
|
+
mail (2.8.1)
|
92
92
|
mini_mime (>= 0.1.1)
|
93
93
|
net-imap
|
94
94
|
net-pop
|
@@ -96,8 +96,7 @@ GEM
|
|
96
96
|
marcel (1.0.2)
|
97
97
|
method_source (1.0.0)
|
98
98
|
mini_mime (1.1.2)
|
99
|
-
|
100
|
-
minitest (5.16.3)
|
99
|
+
minitest (5.18.0)
|
101
100
|
net-imap (0.3.4)
|
102
101
|
date
|
103
102
|
net-protocol
|
@@ -107,39 +106,41 @@ GEM
|
|
107
106
|
timeout
|
108
107
|
net-smtp (0.3.3)
|
109
108
|
net-protocol
|
110
|
-
nio4r (2.5.
|
111
|
-
nokogiri (1.
|
112
|
-
|
109
|
+
nio4r (2.5.9)
|
110
|
+
nokogiri (1.15.2-arm64-darwin)
|
111
|
+
racc (~> 1.4)
|
112
|
+
nokogiri (1.15.2-x86_64-linux)
|
113
113
|
racc (~> 1.4)
|
114
114
|
parallel (1.22.1)
|
115
115
|
parser (3.1.3.0)
|
116
116
|
ast (~> 2.4.1)
|
117
117
|
racc (1.6.2)
|
118
|
-
rack (2.2.
|
119
|
-
rack-test (2.0
|
118
|
+
rack (2.2.7)
|
119
|
+
rack-test (2.1.0)
|
120
120
|
rack (>= 1.3)
|
121
|
-
rails (7.0.
|
122
|
-
actioncable (= 7.0.
|
123
|
-
actionmailbox (= 7.0.
|
124
|
-
actionmailer (= 7.0.
|
125
|
-
actionpack (= 7.0.
|
126
|
-
actiontext (= 7.0.
|
127
|
-
actionview (= 7.0.
|
128
|
-
activejob (= 7.0.
|
129
|
-
activemodel (= 7.0.
|
130
|
-
activerecord (= 7.0.
|
131
|
-
activestorage (= 7.0.
|
132
|
-
activesupport (= 7.0.
|
121
|
+
rails (7.0.5)
|
122
|
+
actioncable (= 7.0.5)
|
123
|
+
actionmailbox (= 7.0.5)
|
124
|
+
actionmailer (= 7.0.5)
|
125
|
+
actionpack (= 7.0.5)
|
126
|
+
actiontext (= 7.0.5)
|
127
|
+
actionview (= 7.0.5)
|
128
|
+
activejob (= 7.0.5)
|
129
|
+
activemodel (= 7.0.5)
|
130
|
+
activerecord (= 7.0.5)
|
131
|
+
activestorage (= 7.0.5)
|
132
|
+
activesupport (= 7.0.5)
|
133
133
|
bundler (>= 1.15.0)
|
134
|
-
railties (= 7.0.
|
134
|
+
railties (= 7.0.5)
|
135
135
|
rails-dom-testing (2.0.3)
|
136
136
|
activesupport (>= 4.2.0)
|
137
137
|
nokogiri (>= 1.6)
|
138
|
-
rails-html-sanitizer (1.
|
139
|
-
loofah (~> 2.
|
140
|
-
|
141
|
-
|
142
|
-
|
138
|
+
rails-html-sanitizer (1.6.0)
|
139
|
+
loofah (~> 2.21)
|
140
|
+
nokogiri (~> 1.14)
|
141
|
+
railties (7.0.5)
|
142
|
+
actionpack (= 7.0.5)
|
143
|
+
activesupport (= 7.0.5)
|
143
144
|
method_source
|
144
145
|
rake (>= 12.2)
|
145
146
|
thor (~> 1.0)
|
@@ -161,15 +162,15 @@ GEM
|
|
161
162
|
rubocop-ast (1.24.1)
|
162
163
|
parser (>= 3.1.1.0)
|
163
164
|
ruby-progressbar (1.11.0)
|
164
|
-
thor (1.2.
|
165
|
-
timeout (0.3.
|
166
|
-
tzinfo (2.0.
|
165
|
+
thor (1.2.2)
|
166
|
+
timeout (0.3.2)
|
167
|
+
tzinfo (2.0.6)
|
167
168
|
concurrent-ruby (~> 1.0)
|
168
169
|
unicode-display_width (2.3.0)
|
169
170
|
websocket-driver (0.7.5)
|
170
171
|
websocket-extensions (>= 0.1.0)
|
171
172
|
websocket-extensions (0.1.5)
|
172
|
-
zeitwerk (2.6.
|
173
|
+
zeitwerk (2.6.8)
|
173
174
|
|
174
175
|
PLATFORMS
|
175
176
|
arm64-darwin-22
|
data/README.md
CHANGED
@@ -47,7 +47,7 @@ In the best case scenario, your observed Largest Contentful Paint times should b
|
|
47
47
|
|
48
48
|
### Worst Case Scenario
|
49
49
|
|
50
|
-
In the worst case, nothing happens. For example, your CDN doesn't support early hints. No problem, you've just added
|
50
|
+
In the worst case, nothing happens. For example, your CDN doesn't support early hints. No problem, you've just added a few bytes of HTTP headers to your responses, it's basically a no-op. You cannot really create new bugs or bad behavior by including this header.
|
51
51
|
## Installation
|
52
52
|
|
53
53
|
Add this line to your application's Gemfile:
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "action_view/helpers/asset_url_helper"
|
4
|
-
require "active_support/concern"
|
5
3
|
require "action_dispatch"
|
6
4
|
|
7
5
|
module RailsHttpPreload
|
@@ -13,7 +11,7 @@ module RailsHttpPreload
|
|
13
11
|
def call(env)
|
14
12
|
response = @app.call(env)
|
15
13
|
|
16
|
-
response[1]["Link"] = preconnect_header if required?(response, ActionDispatch::Request.new(env))
|
14
|
+
response[1]["Link"] = preconnect_header(response) if required?(response, ActionDispatch::Request.new(env))
|
17
15
|
|
18
16
|
response
|
19
17
|
end
|
@@ -21,8 +19,7 @@ module RailsHttpPreload
|
|
21
19
|
# TODO: Should we just add it to every response anyway and let the browser
|
22
20
|
# figure it out?
|
23
21
|
def required?(response, request)
|
24
|
-
html?(response) &&
|
25
|
-
!already_connected?(request)
|
22
|
+
config.asset_host.present? && html?(response) && !already_connected?(request)
|
26
23
|
end
|
27
24
|
|
28
25
|
# Adding this header to, for example, a JSON response would be pointless
|
@@ -31,18 +28,26 @@ module RailsHttpPreload
|
|
31
28
|
response[1]["Content-Type"].match?("html")
|
32
29
|
end
|
33
30
|
|
31
|
+
def current_asset_host
|
32
|
+
ActionController::Base.helpers.compute_asset_host("", host: config.asset_host)
|
33
|
+
end
|
34
|
+
|
34
35
|
# If the asset host is equal to the request domain, no need to add.
|
35
36
|
def already_connected?(request)
|
36
|
-
|
37
|
-
ActionController::Base.helpers.compute_asset_host("", host: config.asset_host) ==
|
38
|
-
ActionController::Base.helpers.compute_asset_host("", { protocol: protocol, host: request.domain })
|
37
|
+
request.base_url == current_asset_host
|
39
38
|
end
|
40
39
|
|
41
|
-
def preconnect_header
|
42
|
-
[
|
43
|
-
|
40
|
+
def preconnect_header(response)
|
41
|
+
header = [
|
42
|
+
current_asset_host,
|
44
43
|
*config.additional_urls
|
45
44
|
].compact.map { |url| create_link_header(url) }.join(", ")
|
45
|
+
|
46
|
+
if response[1]["Link"]
|
47
|
+
"#{header}, #{response[1]["Link"]}"
|
48
|
+
else
|
49
|
+
header
|
50
|
+
end
|
46
51
|
end
|
47
52
|
|
48
53
|
def create_link_header(url)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_http_preload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Berkopec
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
98
|
+
rubygems_version: 3.4.12
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Automatically add an HTTP header to Rails apps to use 103 Early Hints
|