heroku-deflater 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +11 -0
- data/Gemfile +8 -3
- data/Gemfile.lock +165 -45
- data/README.md +16 -12
- data/Rakefile +7 -32
- data/VERSION +1 -1
- data/heroku-deflater.gemspec +17 -57
- data/lib/heroku-deflater/cache_control_manager.rb +25 -0
- data/lib/heroku-deflater/railtie.rb +23 -5
- data/lib/heroku-deflater/serve_zipped_assets.rb +14 -7
- data/lib/heroku-deflater/skip_binary.rb +2 -2
- data/lib/heroku-deflater/version.rb +5 -0
- data/lib/heroku-deflater.rb +6 -0
- metadata +13 -59
- data/spec/fixtures/assets/spec.js +0 -6
- data/spec/fixtures/assets/spec.js.gz +0 -0
- data/spec/fixtures/assets/spec2.js +0 -4
- data/spec/fixtures/non-assets/spec.js.gz +0 -0
- data/spec/serve_zipped_assets_spec.rb +0 -60
- data/spec/skip_binary_spec.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc43fb6e8ecff5ba8ba4a374e79dfd2353c049830026161cb57cfdea433a37dd
|
4
|
+
data.tar.gz: cb450b53c9d7b8cb46f9bdedccbec4b5d88d0eab53cbdc5ab4d7d8318e2ba40e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80c79692c6397ea1c49c63c0a7054ad6de941b5484e2928b0c5724c7aa48b59d1251316b4278a7608edd4e1e89646d1820000f2495b532263c7b2048923e2540
|
7
|
+
data.tar.gz: e3e1738333089af3c793573c091471d825f59dab1803e84acdd2e5390fb4307d7cc25ccae327972e0b767ef86a44f3dd1a20d01ae0c3905c7e73e2291c7dc687
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
2
6
|
|
3
7
|
gem 'rack', '>=1.4.5'
|
4
8
|
|
5
9
|
group :development do
|
6
|
-
gem
|
7
|
-
gem
|
10
|
+
gem 'bundler'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rails', '~>6.0.3.1'
|
8
13
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,54 +1,174 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
heroku-deflater (0.7.0)
|
5
|
+
|
1
6
|
GEM
|
2
|
-
remote:
|
7
|
+
remote: https://rubygems.org/
|
3
8
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
9
|
+
actioncable (6.0.3.7)
|
10
|
+
actionpack (= 6.0.3.7)
|
11
|
+
nio4r (~> 2.0)
|
12
|
+
websocket-driver (>= 0.6.1)
|
13
|
+
actionmailbox (6.0.3.7)
|
14
|
+
actionpack (= 6.0.3.7)
|
15
|
+
activejob (= 6.0.3.7)
|
16
|
+
activerecord (= 6.0.3.7)
|
17
|
+
activestorage (= 6.0.3.7)
|
18
|
+
activesupport (= 6.0.3.7)
|
19
|
+
mail (>= 2.7.1)
|
20
|
+
actionmailer (6.0.3.7)
|
21
|
+
actionpack (= 6.0.3.7)
|
22
|
+
actionview (= 6.0.3.7)
|
23
|
+
activejob (= 6.0.3.7)
|
24
|
+
mail (~> 2.5, >= 2.5.4)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
actionpack (6.0.3.7)
|
27
|
+
actionview (= 6.0.3.7)
|
28
|
+
activesupport (= 6.0.3.7)
|
29
|
+
rack (~> 2.0, >= 2.0.8)
|
30
|
+
rack-test (>= 0.6.3)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
33
|
+
actiontext (6.0.3.7)
|
34
|
+
actionpack (= 6.0.3.7)
|
35
|
+
activerecord (= 6.0.3.7)
|
36
|
+
activestorage (= 6.0.3.7)
|
37
|
+
activesupport (= 6.0.3.7)
|
38
|
+
nokogiri (>= 1.8.5)
|
39
|
+
actionview (6.0.3.7)
|
40
|
+
activesupport (= 6.0.3.7)
|
41
|
+
builder (~> 3.1)
|
42
|
+
erubi (~> 1.4)
|
43
|
+
rails-dom-testing (~> 2.0)
|
44
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
45
|
+
activejob (6.0.3.7)
|
46
|
+
activesupport (= 6.0.3.7)
|
47
|
+
globalid (>= 0.3.6)
|
48
|
+
activemodel (6.0.3.7)
|
49
|
+
activesupport (= 6.0.3.7)
|
50
|
+
activerecord (6.0.3.7)
|
51
|
+
activemodel (= 6.0.3.7)
|
52
|
+
activesupport (= 6.0.3.7)
|
53
|
+
activestorage (6.0.3.7)
|
54
|
+
actionpack (= 6.0.3.7)
|
55
|
+
activejob (= 6.0.3.7)
|
56
|
+
activerecord (= 6.0.3.7)
|
57
|
+
marcel (~> 1.0.0)
|
58
|
+
activesupport (6.0.3.7)
|
59
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
60
|
+
i18n (>= 0.7, < 2)
|
61
|
+
minitest (~> 5.1)
|
62
|
+
tzinfo (~> 1.1)
|
63
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
64
|
+
builder (3.2.4)
|
65
|
+
concurrent-ruby (1.2.2)
|
66
|
+
crass (1.0.6)
|
67
|
+
date (3.3.3)
|
68
|
+
diff-lcs (1.5.0)
|
69
|
+
erubi (1.12.0)
|
70
|
+
globalid (1.1.0)
|
71
|
+
activesupport (>= 5.0)
|
72
|
+
i18n (1.14.1)
|
73
|
+
concurrent-ruby (~> 1.0)
|
74
|
+
loofah (2.21.4)
|
75
|
+
crass (~> 1.0.2)
|
76
|
+
nokogiri (>= 1.12.0)
|
77
|
+
mail (2.8.1)
|
78
|
+
mini_mime (>= 0.1.1)
|
79
|
+
net-imap
|
80
|
+
net-pop
|
81
|
+
net-smtp
|
82
|
+
marcel (1.0.2)
|
83
|
+
method_source (1.0.0)
|
84
|
+
mini_mime (1.1.5)
|
85
|
+
mini_portile2 (2.8.4)
|
86
|
+
minitest (5.20.0)
|
87
|
+
net-imap (0.4.1)
|
88
|
+
date
|
89
|
+
net-protocol
|
90
|
+
net-pop (0.1.2)
|
91
|
+
net-protocol
|
92
|
+
net-protocol (0.2.1)
|
93
|
+
timeout
|
94
|
+
net-smtp (0.4.0)
|
95
|
+
net-protocol
|
96
|
+
nio4r (2.5.9)
|
97
|
+
nokogiri (1.15.4)
|
98
|
+
mini_portile2 (~> 2.8.2)
|
99
|
+
racc (~> 1.4)
|
100
|
+
racc (1.7.1)
|
101
|
+
rack (2.2.8)
|
102
|
+
rack-test (2.1.0)
|
103
|
+
rack (>= 1.3)
|
104
|
+
rails (6.0.3.7)
|
105
|
+
actioncable (= 6.0.3.7)
|
106
|
+
actionmailbox (= 6.0.3.7)
|
107
|
+
actionmailer (= 6.0.3.7)
|
108
|
+
actionpack (= 6.0.3.7)
|
109
|
+
actiontext (= 6.0.3.7)
|
110
|
+
actionview (= 6.0.3.7)
|
111
|
+
activejob (= 6.0.3.7)
|
112
|
+
activemodel (= 6.0.3.7)
|
113
|
+
activerecord (= 6.0.3.7)
|
114
|
+
activestorage (= 6.0.3.7)
|
115
|
+
activesupport (= 6.0.3.7)
|
116
|
+
bundler (>= 1.3.0)
|
117
|
+
railties (= 6.0.3.7)
|
118
|
+
sprockets-rails (>= 2.0.0)
|
119
|
+
rails-dom-testing (2.2.0)
|
120
|
+
activesupport (>= 5.0.0)
|
121
|
+
minitest
|
122
|
+
nokogiri (>= 1.6)
|
123
|
+
rails-html-sanitizer (1.6.0)
|
124
|
+
loofah (~> 2.21)
|
125
|
+
nokogiri (~> 1.14)
|
126
|
+
railties (6.0.3.7)
|
127
|
+
actionpack (= 6.0.3.7)
|
128
|
+
activesupport (= 6.0.3.7)
|
129
|
+
method_source
|
130
|
+
rake (>= 0.8.7)
|
131
|
+
thor (>= 0.20.3, < 2.0)
|
132
|
+
rake (13.0.6)
|
133
|
+
rspec (3.12.0)
|
134
|
+
rspec-core (~> 3.12.0)
|
135
|
+
rspec-expectations (~> 3.12.0)
|
136
|
+
rspec-mocks (~> 3.12.0)
|
137
|
+
rspec-core (3.12.2)
|
138
|
+
rspec-support (~> 3.12.0)
|
139
|
+
rspec-expectations (3.12.3)
|
140
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
141
|
+
rspec-support (~> 3.12.0)
|
142
|
+
rspec-mocks (3.12.6)
|
143
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
144
|
+
rspec-support (~> 3.12.0)
|
145
|
+
rspec-support (3.12.1)
|
146
|
+
sprockets (4.2.1)
|
147
|
+
concurrent-ruby (~> 1.0)
|
148
|
+
rack (>= 2.2.4, < 4)
|
149
|
+
sprockets-rails (3.4.2)
|
150
|
+
actionpack (>= 5.2)
|
151
|
+
activesupport (>= 5.2)
|
152
|
+
sprockets (>= 3.0.0)
|
153
|
+
thor (1.3.0)
|
154
|
+
thread_safe (0.3.6)
|
155
|
+
timeout (0.4.0)
|
156
|
+
tzinfo (1.2.11)
|
157
|
+
thread_safe (~> 0.1)
|
158
|
+
websocket-driver (0.7.6)
|
159
|
+
websocket-extensions (>= 0.1.0)
|
160
|
+
websocket-extensions (0.1.5)
|
161
|
+
zeitwerk (2.6.12)
|
47
162
|
|
48
163
|
PLATFORMS
|
49
164
|
ruby
|
50
165
|
|
51
166
|
DEPENDENCIES
|
52
167
|
bundler
|
53
|
-
|
168
|
+
heroku-deflater!
|
54
169
|
rack (>= 1.4.5)
|
170
|
+
rails (~> 6.0.3.1)
|
171
|
+
rspec
|
172
|
+
|
173
|
+
BUNDLED WITH
|
174
|
+
2.2.33
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# heroku-deflater
|
2
2
|
|
3
|
-
A simple rack middleware that enables compressing of your
|
4
|
-
responses on Heroku, while not wasting CPU
|
5
|
-
and other binary responses.
|
3
|
+
A simple rack middleware that enables compressing of your sprockets and
|
4
|
+
webpacker assets and application responses on Heroku, while not wasting CPU
|
5
|
+
cycles on pointlessly compressing images and other binary responses.
|
6
6
|
|
7
7
|
It also includes code from https://github.com/mattolson/heroku_rails_deflate
|
8
8
|
|
9
|
-
Before serving a file from disk to a gzip-enabled client, it will look for
|
10
|
-
|
11
|
-
|
9
|
+
Before serving a file from disk to a gzip-enabled client, it will look for a
|
10
|
+
precompressed file in the same location that ends in ".gz". The purpose is to
|
11
|
+
avoid compressing the same file each time it is requested.
|
12
12
|
|
13
13
|
## Installing
|
14
14
|
|
@@ -19,17 +19,21 @@ Add to your Gemfile:
|
|
19
19
|
|
20
20
|
## Contributing to heroku-deflater
|
21
21
|
|
22
|
-
* Check out the latest master to make sure the feature hasn't been implemented
|
23
|
-
|
22
|
+
* Check out the latest master to make sure the feature hasn't been implemented
|
23
|
+
or the bug hasn't been fixed yet.
|
24
|
+
* Check out the issue tracker to make sure someone already hasn't requested it
|
25
|
+
and/or contributed it.
|
24
26
|
* Fork the project.
|
25
27
|
* Start a feature/bugfix branch.
|
26
28
|
* Commit and push until you are happy with your contribution.
|
27
|
-
* Make sure to add tests for it. This is important so I don't break it in a
|
28
|
-
|
29
|
+
* Make sure to add tests for it. This is important so I don't break it in a
|
30
|
+
future version unintentionally.
|
31
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to
|
32
|
+
have your own version, or is otherwise necessary, that is fine, but please
|
33
|
+
isolate to its own commit so I can cherry-pick around it.
|
29
34
|
|
30
35
|
## Copyright
|
31
36
|
|
32
|
-
Copyright (c) 2012 Roman Shterenzon. See LICENSE.txt for
|
33
|
-
further details.
|
37
|
+
Copyright (c) 2012 Roman Shterenzon. See LICENSE.txt for further details.
|
34
38
|
|
35
39
|
[1]: https://github.com/rack/rack/issues/349
|
data/Rakefile
CHANGED
@@ -1,42 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'bundler'
|
3
|
+
require 'bundler/gem_tasks'
|
5
4
|
begin
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
rescue LoadError
|
11
8
|
end
|
12
|
-
require 'rake'
|
13
9
|
|
14
|
-
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "heroku-deflater"
|
18
|
-
gem.homepage = "http://github.com/romanbsd/heroku-deflater"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Deflate assets on heroku}
|
21
|
-
gem.description = gem.summary
|
22
|
-
gem.email = "romanbsd@yahoo.com"
|
23
|
-
gem.authors = ["Roman Shterenzon"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
28
|
-
require 'rake/testtask'
|
29
|
-
Rake::TestTask.new(:test) do |test|
|
30
|
-
test.libs << 'lib' << 'test'
|
31
|
-
test.pattern = 'test/**/test_*.rb'
|
32
|
-
test.verbose = true
|
33
|
-
end
|
34
|
-
|
35
|
-
task :default => :test
|
10
|
+
task default: :spec
|
36
11
|
|
37
12
|
require 'rdoc/task'
|
38
13
|
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') :
|
14
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
40
15
|
|
41
16
|
rdoc.rdoc_dir = 'rdoc'
|
42
17
|
rdoc.title = "heroku-deflater #{version}"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
data/heroku-deflater.gemspec
CHANGED
@@ -1,64 +1,24 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: heroku-deflater 0.6.2 ruby lib
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/heroku-deflater/version'
|
6
4
|
|
7
5
|
Gem::Specification.new do |s|
|
8
|
-
s.name =
|
9
|
-
s.version =
|
6
|
+
s.name = 'heroku-deflater'
|
7
|
+
s.version = HerokuDeflater::VERSION
|
8
|
+
s.authors = ['Roman Shterenzon']
|
9
|
+
s.email = 'romanbsd@yahoo.com'
|
10
10
|
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.email = "romanbsd@yahoo.com"
|
11
|
+
s.summary = 'Deflate assets on heroku'
|
12
|
+
s.description = 'Deflate assets on Heroku'
|
13
|
+
s.homepage = 'https://github.com/romanbsd/heroku-deflater'
|
14
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
15
|
+
s.require_paths = ['lib']
|
17
16
|
s.extra_rdoc_files = [
|
18
|
-
|
19
|
-
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".rspec",
|
23
|
-
"Gemfile",
|
24
|
-
"Gemfile.lock",
|
25
|
-
"LICENSE.txt",
|
26
|
-
"README.md",
|
27
|
-
"Rakefile",
|
28
|
-
"VERSION",
|
29
|
-
"heroku-deflater.gemspec",
|
30
|
-
"lib/heroku-deflater.rb",
|
31
|
-
"lib/heroku-deflater/railtie.rb",
|
32
|
-
"lib/heroku-deflater/serve_zipped_assets.rb",
|
33
|
-
"lib/heroku-deflater/skip_binary.rb",
|
34
|
-
"spec/fixtures/assets/spec.js",
|
35
|
-
"spec/fixtures/assets/spec.js.gz",
|
36
|
-
"spec/fixtures/assets/spec2.js",
|
37
|
-
"spec/fixtures/non-assets/spec.js.gz",
|
38
|
-
"spec/serve_zipped_assets_spec.rb",
|
39
|
-
"spec/skip_binary_spec.rb"
|
17
|
+
'LICENSE.txt',
|
18
|
+
'README.md'
|
40
19
|
]
|
41
|
-
s.
|
42
|
-
s.
|
43
|
-
|
44
|
-
s.summary = "Deflate assets on heroku"
|
45
|
-
|
46
|
-
if s.respond_to? :specification_version then
|
47
|
-
s.specification_version = 4
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_runtime_dependency(%q<rack>, [">= 1.4.5"])
|
51
|
-
s.add_development_dependency(%q<bundler>, [">= 0"])
|
52
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<rack>, [">= 1.4.5"])
|
55
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
56
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
57
|
-
end
|
58
|
-
else
|
59
|
-
s.add_dependency(%q<rack>, [">= 1.4.5"])
|
60
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
61
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
20
|
+
s.licenses = ['MIT']
|
21
|
+
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
62
23
|
end
|
63
24
|
end
|
64
|
-
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module HerokuDeflater
|
2
|
+
class CacheControlManager
|
3
|
+
DEFAULT_MAX_AGE = '86400'.freeze
|
4
|
+
attr_reader :app, :max_age
|
5
|
+
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
@max_age = DEFAULT_MAX_AGE
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_max_age(max_age)
|
12
|
+
@max_age = max_age
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache_control_headers
|
16
|
+
if HerokuDeflater.rails_version_5?
|
17
|
+
headers = app.config.public_file_server.headers ||= {}
|
18
|
+
headers['Cache-Control'] ||= "public, max-age=#{max_age}"
|
19
|
+
headers
|
20
|
+
else
|
21
|
+
app.config.static_cache_control ||= "public, max-age=#{max_age}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,20 +1,38 @@
|
|
1
1
|
require 'rack/deflater'
|
2
2
|
require 'heroku-deflater/skip_binary'
|
3
3
|
require 'heroku-deflater/serve_zipped_assets'
|
4
|
+
require 'heroku-deflater/cache_control_manager'
|
4
5
|
|
5
6
|
module HerokuDeflater
|
6
7
|
class Railtie < Rails::Railtie
|
7
8
|
initializer 'heroku_deflater.configure_rails_initialization' do |app|
|
8
9
|
app.middleware.insert_before ActionDispatch::Static, Rack::Deflater
|
9
10
|
app.middleware.insert_before ActionDispatch::Static, HerokuDeflater::SkipBinary
|
10
|
-
|
11
|
-
|
11
|
+
|
12
|
+
assets_prefix = app.config.assets.prefix if app.config.respond_to?(:assets)
|
13
|
+
|
14
|
+
if Object.const_defined?(:Webpacker)
|
15
|
+
public_path = Webpacker.config.public_path.to_s
|
16
|
+
public_output_path = Webpacker.config.public_output_path.to_s
|
17
|
+
webpacker_prefix = public_output_path.split(public_path).last
|
18
|
+
end
|
19
|
+
|
20
|
+
if assets_prefix || webpacker_prefix
|
21
|
+
paths = [assets_prefix, webpacker_prefix].compact
|
22
|
+
app.middleware.insert_before Rack::Deflater, HerokuDeflater::ServeZippedAssets,
|
23
|
+
app.paths['public'].first, paths, self.class.cache_control_manager(app)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.cache_control_manager(app)
|
28
|
+
@_cache_control_manager ||= CacheControlManager.new(app)
|
12
29
|
end
|
13
30
|
|
14
|
-
# Set default Cache-Control headers to
|
31
|
+
# Set default Cache-Control headers to 24 hours.
|
15
32
|
# The configuration block in config/application.rb overrides this.
|
16
|
-
config.
|
17
|
-
|
33
|
+
config.before_initialize do |app|
|
34
|
+
cache_control = cache_control_manager(app)
|
35
|
+
cache_control.setup_max_age(86400)
|
18
36
|
end
|
19
37
|
end
|
20
38
|
end
|
@@ -1,19 +1,26 @@
|
|
1
1
|
require 'action_controller'
|
2
|
-
require 'active_support/core_ext/uri'
|
3
2
|
require 'action_dispatch/middleware/static'
|
4
3
|
|
4
|
+
if Rails::VERSION::MAJOR < 7
|
5
|
+
# Deprecated in Rails 7.0, and removed in 7.1
|
6
|
+
require 'active_support/core_ext/uri'
|
7
|
+
end
|
8
|
+
|
5
9
|
# Adapted from https://gist.github.com/guyboltonking/2152663
|
6
10
|
#
|
7
11
|
# Taken from: https://github.com/mattolson/heroku_rails_deflate
|
8
12
|
#
|
9
|
-
|
10
13
|
module HerokuDeflater
|
11
14
|
class ServeZippedAssets
|
12
|
-
def initialize(app, root,
|
15
|
+
def initialize(app, root, paths, cache_control_manager)
|
13
16
|
@app = app
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
+
@paths = paths.map { |p| p.chomp('/') + '/' }
|
18
|
+
|
19
|
+
if HerokuDeflater.rails_version_5?
|
20
|
+
@file_handler = ActionDispatch::FileHandler.new(root, headers: cache_control_manager.cache_control_headers)
|
21
|
+
else
|
22
|
+
@file_handler = ActionDispatch::FileHandler.new(root, cache_control_manager.cache_control_headers)
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
def call(env)
|
@@ -25,7 +32,7 @@ module HerokuDeflater
|
|
25
32
|
# See if gzipped version exists in assets directory
|
26
33
|
compressed_path = env['PATH_INFO'] + '.gz'
|
27
34
|
|
28
|
-
if compressed_path.start_with?(
|
35
|
+
if compressed_path.start_with?(*@paths) && (match = @file_handler.match?(compressed_path))
|
29
36
|
# Get the FileHandler to serve up the gzipped file, then strip the .gz suffix
|
30
37
|
env['PATH_INFO'] = match
|
31
38
|
status, headers, body = @file_handler.call(env)
|
@@ -8,7 +8,7 @@ module HerokuDeflater
|
|
8
8
|
WHITELIST = [
|
9
9
|
%r{^text/},
|
10
10
|
'application/javascript',
|
11
|
-
%r{^application
|
11
|
+
%r{^application/.*?json},
|
12
12
|
%r{^application/.*?xml},
|
13
13
|
'application/x-font-ttf',
|
14
14
|
'font/opentype',
|
@@ -21,7 +21,7 @@ module HerokuDeflater
|
|
21
21
|
content_type = headers['Content-Type']
|
22
22
|
cache_control = headers['Cache-Control'].to_s.downcase
|
23
23
|
|
24
|
-
unless cache_control.include?('no-transform')
|
24
|
+
unless cache_control.include?('no-transform') || WHITELIST.any? { |type| type === content_type }
|
25
25
|
if cache_control.empty?
|
26
26
|
headers['Cache-Control'] = 'no-transform'
|
27
27
|
else
|
data/lib/heroku-deflater.rb
CHANGED
metadata
CHANGED
@@ -1,58 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku-deflater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Shterenzon
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: rack
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.4.5
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.4.5
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
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: jeweler
|
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: Deflate assets on heroku
|
11
|
+
date: 2023-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Deflate assets on Heroku
|
56
14
|
email: romanbsd@yahoo.com
|
57
15
|
executables: []
|
58
16
|
extensions: []
|
@@ -60,6 +18,7 @@ extra_rdoc_files:
|
|
60
18
|
- LICENSE.txt
|
61
19
|
- README.md
|
62
20
|
files:
|
21
|
+
- ".gitignore"
|
63
22
|
- ".rspec"
|
64
23
|
- Gemfile
|
65
24
|
- Gemfile.lock
|
@@ -69,20 +28,16 @@ files:
|
|
69
28
|
- VERSION
|
70
29
|
- heroku-deflater.gemspec
|
71
30
|
- lib/heroku-deflater.rb
|
31
|
+
- lib/heroku-deflater/cache_control_manager.rb
|
72
32
|
- lib/heroku-deflater/railtie.rb
|
73
33
|
- lib/heroku-deflater/serve_zipped_assets.rb
|
74
34
|
- lib/heroku-deflater/skip_binary.rb
|
75
|
-
-
|
76
|
-
|
77
|
-
- spec/fixtures/assets/spec2.js
|
78
|
-
- spec/fixtures/non-assets/spec.js.gz
|
79
|
-
- spec/serve_zipped_assets_spec.rb
|
80
|
-
- spec/skip_binary_spec.rb
|
81
|
-
homepage: http://github.com/romanbsd/heroku-deflater
|
35
|
+
- lib/heroku-deflater/version.rb
|
36
|
+
homepage: https://github.com/romanbsd/heroku-deflater
|
82
37
|
licenses:
|
83
38
|
- MIT
|
84
39
|
metadata: {}
|
85
|
-
post_install_message:
|
40
|
+
post_install_message:
|
86
41
|
rdoc_options: []
|
87
42
|
require_paths:
|
88
43
|
- lib
|
@@ -90,16 +45,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
45
|
requirements:
|
91
46
|
- - ">="
|
92
47
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
48
|
+
version: 2.3.0
|
94
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
50
|
requirements:
|
96
51
|
- - ">="
|
97
52
|
- !ruby/object:Gem::Version
|
98
53
|
version: '0'
|
99
54
|
requirements: []
|
100
|
-
|
101
|
-
|
102
|
-
signing_key:
|
55
|
+
rubygems_version: 3.2.33
|
56
|
+
signing_key:
|
103
57
|
specification_version: 4
|
104
58
|
summary: Deflate assets on heroku
|
105
59
|
test_files: []
|
Binary file
|
Binary file
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'rack/mock'
|
2
|
-
require 'rack/static'
|
3
|
-
require 'heroku-deflater/serve_zipped_assets'
|
4
|
-
|
5
|
-
describe HerokuDeflater::ServeZippedAssets do
|
6
|
-
def process(path, accept_encoding = 'compress, gzip, deflate')
|
7
|
-
env = Rack::MockRequest.env_for(path)
|
8
|
-
env['HTTP_ACCEPT_ENCODING'] = accept_encoding
|
9
|
-
app.call(env)
|
10
|
-
end
|
11
|
-
|
12
|
-
def app
|
13
|
-
@app ||= begin
|
14
|
-
root_path = File.expand_path('../fixtures', __FILE__)
|
15
|
-
cache_control = 'public, max-age=86400'
|
16
|
-
mock = lambda { |env| [404, {'X-Cascade' => 'pass'}, []] }
|
17
|
-
described_class.new(mock, root_path, '/assets', cache_control)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'does nothing for clients which do not want gzip' do
|
22
|
-
status, headers, body = process('/assets/spec.js', nil)
|
23
|
-
status.should eq(404)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'handles the pre-gzipped assets' do
|
27
|
-
status, headers, body = process('/assets/spec.js')
|
28
|
-
status.should eq(200)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'has correct content type' do
|
32
|
-
status, headers, body = process('/assets/spec.js')
|
33
|
-
headers['Content-Type'].should eq('application/javascript')
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'has correct content encoding' do
|
37
|
-
status, headers, body = process('/assets/spec.js')
|
38
|
-
headers['Content-Encoding'].should eq('gzip')
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'has correct content length' do
|
42
|
-
status, headers, body = process('/assets/spec.js')
|
43
|
-
headers['Content-Length'].should eq('86')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'has correct cache control' do
|
47
|
-
status, headers, body = process('/assets/spec.js')
|
48
|
-
headers['Cache-Control'].should eq('public, max-age=86400')
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'does not serve non-gzipped assets' do
|
52
|
-
status, headers, body = process('/assets/spec2.js')
|
53
|
-
status.should eq(404)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'does not serve anything from non-asset directories' do
|
57
|
-
status, headers, body = process('/non-assets/spec.js')
|
58
|
-
status.should eq(404)
|
59
|
-
end
|
60
|
-
end
|
data/spec/skip_binary_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'rack/mock'
|
2
|
-
require 'heroku-deflater/skip_binary'
|
3
|
-
|
4
|
-
describe HerokuDeflater::SkipBinary do
|
5
|
-
let(:env) { Rack::MockRequest.env_for('/') }
|
6
|
-
|
7
|
-
def app_returning_type(type, headers = {})
|
8
|
-
lambda { |env| [200, {'Content-Type' => type}.merge(headers), ['']] }
|
9
|
-
end
|
10
|
-
|
11
|
-
def process(type, headers = {})
|
12
|
-
described_class.new(app_returning_type(type, headers)).call(env)[1]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "forbids compressing of binary types" do
|
16
|
-
%w[application/gzip application/pdf image/jpeg].each do |type|
|
17
|
-
headers = process(type)
|
18
|
-
headers['Cache-Control'].to_s.should include('no-transform')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "allows compressing of text types" do
|
23
|
-
%w[text/plain text/html application/json application/javascript
|
24
|
-
application/rss+xml].each do |type|
|
25
|
-
headers = process(type)
|
26
|
-
headers['Cache-Control'].to_s.should_not include('no-transform')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "adds to existing headers" do
|
31
|
-
headers = process('image/gif', 'Cache-Control' => 'public')
|
32
|
-
headers['Cache-Control'].should eq('public, no-transform')
|
33
|
-
end
|
34
|
-
|
35
|
-
it "doesn't add 'no-transform' if it's already present" do
|
36
|
-
headers = process('image/gif', 'Cache-Control' => 'public, no-transform')
|
37
|
-
headers['Cache-Control'].should eq('public, no-transform')
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|