tome-oauth-io-bible-heroku-deflater 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 62f77d2c492cdbda150ed216ee81829684ac170272523cccae7aec3a4356f15e
4
+ data.tar.gz: f05c326903de85848497ddf22aa677e02809fceae3a212f9743defb331e92df9
5
+ SHA512:
6
+ metadata.gz: 6d959cf3310a3ac0a11c8db304566e4775600e95b6e2c755ce2c2c00e608c02b5369442c3e1de070701e7018d868e3abf9e29ca10d722c9b3cecd81d346f269a
7
+ data.tar.gz: '0503818bbe1893407512e0ba94d183d680367f43544a319eed296b525fe7c6a01cb77092b69307c12e3c5a0f14245d3af6d7aeae96cb548f061e05849ca2cfde'
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format progress
3
+ --tag ~slow
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rack', '>=1.4.5'
4
+
5
+ group :development do
6
+ gem "bundler"
7
+ gem "jeweler"
8
+ gem "rspec"
9
+ gem "rails"
10
+ end
@@ -0,0 +1,170 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actioncable (5.0.1)
5
+ actionpack (= 5.0.1)
6
+ nio4r (~> 1.2)
7
+ websocket-driver (~> 0.6.1)
8
+ actionmailer (5.0.1)
9
+ actionpack (= 5.0.1)
10
+ actionview (= 5.0.1)
11
+ activejob (= 5.0.1)
12
+ mail (~> 2.5, >= 2.5.4)
13
+ rails-dom-testing (~> 2.0)
14
+ actionpack (5.0.1)
15
+ actionview (= 5.0.1)
16
+ activesupport (= 5.0.1)
17
+ rack (~> 2.0)
18
+ rack-test (~> 0.6.3)
19
+ rails-dom-testing (~> 2.0)
20
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
21
+ actionview (5.0.1)
22
+ activesupport (= 5.0.1)
23
+ builder (~> 3.1)
24
+ erubis (~> 2.7.0)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ activejob (5.0.1)
28
+ activesupport (= 5.0.1)
29
+ globalid (>= 0.3.6)
30
+ activemodel (5.0.1)
31
+ activesupport (= 5.0.1)
32
+ activerecord (5.0.1)
33
+ activemodel (= 5.0.1)
34
+ activesupport (= 5.0.1)
35
+ arel (~> 7.0)
36
+ activesupport (5.0.1)
37
+ concurrent-ruby (~> 1.0, >= 1.0.2)
38
+ i18n (~> 0.7)
39
+ minitest (~> 5.1)
40
+ tzinfo (~> 1.1)
41
+ addressable (2.5.0)
42
+ public_suffix (~> 2.0, >= 2.0.2)
43
+ arel (7.1.4)
44
+ builder (3.2.3)
45
+ concurrent-ruby (1.0.4)
46
+ descendants_tracker (0.0.4)
47
+ thread_safe (~> 0.3, >= 0.3.1)
48
+ diff-lcs (1.3)
49
+ erubis (2.7.0)
50
+ faraday (0.9.2)
51
+ multipart-post (>= 1.2, < 3)
52
+ git (1.3.0)
53
+ github_api (0.11.3)
54
+ addressable (~> 2.3)
55
+ descendants_tracker (~> 0.0.1)
56
+ faraday (~> 0.8, < 0.10)
57
+ hashie (>= 1.2)
58
+ multi_json (>= 1.7.5, < 2.0)
59
+ nokogiri (~> 1.6.0)
60
+ oauth2
61
+ globalid (0.3.7)
62
+ activesupport (>= 4.1.0)
63
+ hashie (3.4.6)
64
+ highline (1.7.8)
65
+ i18n (0.7.0)
66
+ jeweler (2.3.3)
67
+ builder
68
+ bundler (>= 1.0)
69
+ git (>= 1.2.5)
70
+ github_api (~> 0.11.0)
71
+ highline (>= 1.6.15)
72
+ nokogiri (>= 1.5.10)
73
+ psych (~> 2.2)
74
+ rake
75
+ rdoc
76
+ semver2
77
+ jwt (1.5.6)
78
+ loofah (2.0.3)
79
+ nokogiri (>= 1.5.9)
80
+ mail (2.6.4)
81
+ mime-types (>= 1.16, < 4)
82
+ method_source (0.8.2)
83
+ mime-types (3.1)
84
+ mime-types-data (~> 3.2015)
85
+ mime-types-data (3.2016.0521)
86
+ mini_portile2 (2.1.0)
87
+ minitest (5.10.1)
88
+ multi_json (1.12.1)
89
+ multi_xml (0.6.0)
90
+ multipart-post (2.0.0)
91
+ nio4r (1.2.1)
92
+ nokogiri (1.6.8.1)
93
+ mini_portile2 (~> 2.1.0)
94
+ oauth2 (1.3.0)
95
+ faraday (>= 0.8, < 0.11)
96
+ jwt (~> 1.0)
97
+ multi_json (~> 1.3)
98
+ multi_xml (~> 0.5)
99
+ rack (>= 1.2, < 3)
100
+ psych (2.2.2)
101
+ public_suffix (2.0.5)
102
+ rack (2.0.1)
103
+ rack-test (0.6.3)
104
+ rack (>= 1.0)
105
+ rails (5.0.1)
106
+ actioncable (= 5.0.1)
107
+ actionmailer (= 5.0.1)
108
+ actionpack (= 5.0.1)
109
+ actionview (= 5.0.1)
110
+ activejob (= 5.0.1)
111
+ activemodel (= 5.0.1)
112
+ activerecord (= 5.0.1)
113
+ activesupport (= 5.0.1)
114
+ bundler (>= 1.3.0, < 2.0)
115
+ railties (= 5.0.1)
116
+ sprockets-rails (>= 2.0.0)
117
+ rails-dom-testing (2.0.2)
118
+ activesupport (>= 4.2.0, < 6.0)
119
+ nokogiri (~> 1.6)
120
+ rails-html-sanitizer (1.0.3)
121
+ loofah (~> 2.0)
122
+ railties (5.0.1)
123
+ actionpack (= 5.0.1)
124
+ activesupport (= 5.0.1)
125
+ method_source
126
+ rake (>= 0.8.7)
127
+ thor (>= 0.18.1, < 2.0)
128
+ rake (12.0.0)
129
+ rdoc (5.0.0)
130
+ rspec (3.5.0)
131
+ rspec-core (~> 3.5.0)
132
+ rspec-expectations (~> 3.5.0)
133
+ rspec-mocks (~> 3.5.0)
134
+ rspec-core (3.5.4)
135
+ rspec-support (~> 3.5.0)
136
+ rspec-expectations (3.5.0)
137
+ diff-lcs (>= 1.2.0, < 2.0)
138
+ rspec-support (~> 3.5.0)
139
+ rspec-mocks (3.5.0)
140
+ diff-lcs (>= 1.2.0, < 2.0)
141
+ rspec-support (~> 3.5.0)
142
+ rspec-support (3.5.0)
143
+ semver2 (3.4.2)
144
+ sprockets (3.7.1)
145
+ concurrent-ruby (~> 1.0)
146
+ rack (> 1, < 3)
147
+ sprockets-rails (3.2.0)
148
+ actionpack (>= 4.0)
149
+ activesupport (>= 4.0)
150
+ sprockets (>= 3.0.0)
151
+ thor (0.19.4)
152
+ thread_safe (0.3.5)
153
+ tzinfo (1.2.2)
154
+ thread_safe (~> 0.1)
155
+ websocket-driver (0.6.5)
156
+ websocket-extensions (>= 0.1.0)
157
+ websocket-extensions (0.1.2)
158
+
159
+ PLATFORMS
160
+ ruby
161
+
162
+ DEPENDENCIES
163
+ bundler
164
+ jeweler
165
+ rack (>= 1.4.5)
166
+ rails
167
+ rspec
168
+
169
+ BUNDLED WITH
170
+ 1.14.2
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Roman Shterenzon
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # heroku-deflater
2
+
3
+ A simple rack middleware that enables compressing of your assets and application
4
+ responses on Heroku, while not wasting CPU cycles on pointlessly compressing images
5
+ and other binary responses.
6
+
7
+ It also includes code from https://github.com/mattolson/heroku_rails_deflate
8
+
9
+ Before serving a file from disk to a gzip-enabled client, it will look for
10
+ a precompressed file in the same location that ends in ".gz".
11
+ The purpose is to avoid compressing the same file each time it is requested.
12
+
13
+ ## Installing
14
+
15
+ Add to your Gemfile:
16
+
17
+ gem 'heroku-deflater', :group => :production
18
+
19
+
20
+ ## Contributing to heroku-deflater
21
+
22
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
23
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
24
+ * Fork the project.
25
+ * Start a feature/bugfix branch.
26
+ * 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 future version unintentionally.
28
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
29
+
30
+ ## Copyright
31
+
32
+ Copyright (c) 2012 Roman Shterenzon. See LICENSE.txt for
33
+ further details.
34
+
35
+ [1]: https://github.com/rack/rack/issues/349
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
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 = "tome-oauth-io-bible-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
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "heroku-deflater #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: heroku-deflater 0.6.3 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "tome-oauth-io-bible-heroku-deflater".freeze
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Roman Shterenzon".freeze]
14
+ s.date = "2018-10-29"
15
+ s.description = "Fork heroku-deflater with fixes for custom cache expiration time setting".freeze
16
+ s.email = "romanbsd@yahoo.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
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/cache_control_manager.rb",
32
+ "lib/heroku-deflater/railtie.rb",
33
+ "lib/heroku-deflater/serve_zipped_assets.rb",
34
+ "lib/heroku-deflater/skip_binary.rb",
35
+ "spec/cache_control_manager_spec.rb",
36
+ "spec/fixtures/assets/spec.js",
37
+ "spec/fixtures/assets/spec.js.gz",
38
+ "spec/fixtures/assets/spec2.js",
39
+ "spec/fixtures/non-assets/spec.js.gz",
40
+ "spec/serve_zipped_assets_spec.rb",
41
+ "spec/skip_binary_spec.rb"
42
+ ]
43
+ s.homepage = "http://github.com/romanbsd/heroku-deflater".freeze
44
+ s.licenses = ["MIT".freeze]
45
+ s.rubygems_version = "2.6.8".freeze
46
+ s.summary = "Deflate assets on heroku".freeze
47
+
48
+ if s.respond_to? :specification_version then
49
+ s.specification_version = 4
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<rack>.freeze, [">= 1.4.5"])
53
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
54
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
55
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
56
+ s.add_development_dependency(%q<rails>.freeze, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<rack>.freeze, [">= 1.4.5"])
59
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
60
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
61
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
62
+ s.add_dependency(%q<rails>.freeze, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<rack>.freeze, [">= 1.4.5"])
66
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
67
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
68
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
69
+ s.add_dependency(%q<rails>.freeze, [">= 0"])
70
+ end
71
+ end
72
+
@@ -0,0 +1 @@
1
+ require 'heroku-deflater/railtie'
@@ -0,0 +1,31 @@
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 rails_version_5?
17
+ headers = app.config.public_file_server.headers ||= {}
18
+ headers['Cache-Control'] ||= "public, max-age=#{max_age}"
19
+ else
20
+ headers = app.config.static_cache_control
21
+ end
22
+ headers
23
+ end
24
+
25
+ private
26
+
27
+ def rails_version_5?
28
+ Rails::VERSION::MAJOR >= 5
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ require 'rack/deflater'
2
+ require 'heroku-deflater/skip_binary'
3
+ require 'heroku-deflater/serve_zipped_assets'
4
+ require 'heroku-deflater/cache_control_manager'
5
+
6
+ module HerokuDeflater
7
+ class Railtie < Rails::Railtie
8
+ initializer 'heroku_deflater.configure_rails_initialization' do |app|
9
+ app.middleware.insert_before ActionDispatch::Static, Rack::Deflater
10
+ app.middleware.insert_before ActionDispatch::Static, HerokuDeflater::SkipBinary
11
+ app.middleware.insert_before Rack::Deflater, HerokuDeflater::ServeZippedAssets,
12
+ app.paths['public'].first, app.config.assets.prefix, self.class.cache_control_manager(app)
13
+ end
14
+
15
+ # Set default Cache-Control headers to 24 hours.
16
+ # The configuration block in config/application.rb overrides this.
17
+ config.before_initialize do |app|
18
+ cache_control = cache_control_manager(app)
19
+ cache_control.setup_max_age(86400)
20
+ end
21
+
22
+ def self.cache_control_manager(app)
23
+ @_cache_control_manager ||= CacheControlManager.new(app)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,62 @@
1
+ require 'action_controller'
2
+ require 'active_support/core_ext/uri'
3
+ require 'action_dispatch/middleware/static'
4
+
5
+ # Adapted from https://gist.github.com/guyboltonking/2152663
6
+ #
7
+ # Taken from: https://github.com/mattolson/heroku_rails_deflate
8
+ #
9
+
10
+ module HerokuDeflater
11
+ class ServeZippedAssets
12
+ def initialize(app, root, assets_path, cache_control_manager)
13
+ @app = app
14
+ @assets_path = assets_path.chomp('/') + '/'
15
+ if rails_version_5?
16
+ @file_handler = ActionDispatch::FileHandler.new(root, headers: cache_control_manager.cache_control_headers)
17
+ else
18
+ @file_handler = ActionDispatch::FileHandler.new(root, cache_control_manager.cache_control_headers)
19
+ end
20
+ end
21
+
22
+ def call(env)
23
+ if env['REQUEST_METHOD'] == 'GET'
24
+ request = Rack::Request.new(env)
25
+ encoding = Rack::Utils.select_best_encoding(%w(gzip identity), request.accept_encoding)
26
+
27
+ if encoding == 'gzip'
28
+ # See if gzipped version exists in assets directory
29
+ compressed_path = env['PATH_INFO'] + '.gz'
30
+
31
+ if compressed_path.start_with?(@assets_path) && (match = @file_handler.match?(compressed_path))
32
+ # Get the FileHandler to serve up the gzipped file, then strip the .gz suffix
33
+ env['PATH_INFO'] = match
34
+ status, headers, body = @file_handler.call(env)
35
+ env['PATH_INFO'].chomp!('.gz')
36
+
37
+ # Set the Vary HTTP header.
38
+ vary = headers['Vary'].to_s.split(',').map(&:strip)
39
+
40
+ unless vary.include?('*') || vary.include?('Accept-Encoding')
41
+ headers['Vary'] = vary.push('Accept-Encoding').join(',')
42
+ end
43
+
44
+ # Add encoding and type
45
+ headers['Content-Encoding'] = 'gzip'
46
+ headers['Content-Type'] = Rack::Mime.mime_type(File.extname(env['PATH_INFO']), 'text/plain')
47
+
48
+ body.close if body.respond_to?(:close)
49
+ return [status, headers, body]
50
+ end
51
+ end
52
+ end
53
+
54
+ @app.call(env)
55
+ end
56
+
57
+ private
58
+ def rails_version_5?
59
+ Rails::VERSION::MAJOR >= 5
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,36 @@
1
+ module HerokuDeflater
2
+ # Add a no-transform Cache-Control header to binary types, so they won't get gzipped
3
+ class SkipBinary
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ WHITELIST = [
9
+ %r{^text/},
10
+ 'application/javascript',
11
+ %r{^application/.*?json},
12
+ %r{^application/.*?xml},
13
+ 'application/x-font-ttf',
14
+ 'font/opentype',
15
+ 'image/svg+xml'
16
+ ].freeze
17
+
18
+ def call(env)
19
+ status, headers, body = @app.call(env)
20
+ headers = Rack::Utils::HeaderHash.new(headers)
21
+ content_type = headers['Content-Type']
22
+ cache_control = headers['Cache-Control'].to_s.downcase
23
+
24
+ unless cache_control.include?('no-transform') || WHITELIST.any? { |type| type === content_type }
25
+ if cache_control.empty?
26
+ headers['Cache-Control'] = 'no-transform'
27
+ else
28
+ headers['Cache-Control'] += ', no-transform'
29
+ end
30
+ end
31
+
32
+ body.close if body.respond_to?(:close)
33
+ [status, headers, body]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,68 @@
1
+ require 'heroku-deflater/cache_control_manager'
2
+ require 'rails'
3
+
4
+ describe HerokuDeflater::CacheControlManager do
5
+ class Rails5App
6
+ def config
7
+ @_config ||= Config.new
8
+ end
9
+
10
+ class Config
11
+ attr_accessor :headers
12
+
13
+ def initialize
14
+ @headers = {}
15
+ end
16
+
17
+ def public_file_server
18
+ self
19
+ end
20
+ end
21
+ end
22
+
23
+ class Rails4App
24
+ def config
25
+ @_config ||= Config.new
26
+ end
27
+
28
+ class Config
29
+ attr_accessor :static_cache_control
30
+ end
31
+ end
32
+
33
+ context 'Rails 4.x and below' do
34
+ let(:app) { Rails4App.new }
35
+
36
+ subject { described_class.new(app) }
37
+ before do
38
+ allow(subject).to receive(:rails_version_5?).and_return(false)
39
+ subject.setup_max_age(86400)
40
+ end
41
+
42
+ it 'sets max age for static_cache_control config option' do
43
+ expect(app.config.static_cache_control).to eq('public, max-age=86400')
44
+ end
45
+
46
+ it 'cache_control_headers returns cache control option' do
47
+ expect(subject.cache_control_headers).to eq('public, max-age=86400')
48
+ end
49
+ end
50
+
51
+ context 'Rails 5' do
52
+ let(:app) { Rails5App.new }
53
+
54
+ subject { described_class.new(app) }
55
+ before do
56
+ allow(subject).to receive(:rails_version_5?).and_return(true)
57
+ subject.setup_max_age(86400)
58
+ end
59
+
60
+ it 'sets max age for public_file_server config option' do
61
+ expect(app.config.public_file_server.headers['Cache-Control']).to eq('public, max-age=86400')
62
+ end
63
+
64
+ it 'cache_control_headers returns hash cache control headers' do
65
+ expect(subject.cache_control_headers).to eq({'Cache-Control' =>'public, max-age=86400'})
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,6 @@
1
+ // Fixture file
2
+ (function() {
3
+ console.log("Hello world");
4
+ console.log("Hello world");
5
+ console.log("Hello world");
6
+ })();
@@ -0,0 +1,4 @@
1
+ // Fixture file
2
+ (function() {
3
+ console.log("Hello world");
4
+ })();
@@ -0,0 +1,80 @@
1
+ require 'rack/mock'
2
+ require 'rack/static'
3
+ require 'heroku-deflater/serve_zipped_assets'
4
+ require 'heroku-deflater/cache_control_manager'
5
+
6
+ describe HerokuDeflater::ServeZippedAssets do
7
+ def process(path, accept_encoding = 'compress, gzip, deflate')
8
+ env = Rack::MockRequest.env_for(path)
9
+ env['HTTP_ACCEPT_ENCODING'] = accept_encoding
10
+ app.call(env)
11
+ end
12
+
13
+ def app
14
+ @app ||= begin
15
+ root_path = File.expand_path('../fixtures', __FILE__)
16
+ cache_control_manager = HerokuDeflater::CacheControlManager.new(nil)
17
+ mock = lambda { |env| [404, {'X-Cascade' => 'pass'}, []] }
18
+ described_class.new(mock, root_path, '/assets', cache_control_manager)
19
+ end
20
+ end
21
+
22
+ shared_examples_for 'ServeZippedAssets' do
23
+
24
+ it 'does nothing for clients which do not want gzip' do
25
+ status, headers, body = process('/assets/spec.js', nil)
26
+ expect(status).to eq(404)
27
+ end
28
+
29
+ it 'handles the pre-gzipped assets' do
30
+ status, headers, body = process('/assets/spec.js')
31
+ expect(status).to eq(200)
32
+ end
33
+
34
+ it 'has correct content type' do
35
+ status, headers, body = process('/assets/spec.js')
36
+ expect(headers['Content-Type']).to eq('application/javascript')
37
+ end
38
+
39
+ it 'has correct content encoding' do
40
+ status, headers, body = process('/assets/spec.js')
41
+ expect(headers['Content-Encoding']).to eq('gzip')
42
+ end
43
+
44
+ it 'has correct content length' do
45
+ status, headers, body = process('/assets/spec.js')
46
+ expect(headers['Content-Length']).to eq('86')
47
+ end
48
+
49
+ it 'has correct cache control' do
50
+ status, headers, body = process('/assets/spec.js')
51
+ expect(headers['Cache-Control']).to eq('public, max-age=86400')
52
+ end
53
+
54
+ it 'does not serve non-gzipped assets' do
55
+ status, headers, body = process('/assets/spec2.js')
56
+ expect(status).to eq(404)
57
+ end
58
+
59
+ it 'does not serve anything from non-asset directories' do
60
+ status, headers, body = process('/non-assets/spec.js')
61
+ expect(status).to eq(404)
62
+ end
63
+ end
64
+
65
+ describe 'Rais 4.x' do
66
+ before do
67
+ allow(app).to receive(:rails_version_5?) { false }
68
+ end
69
+
70
+ it_behaves_like 'ServeZippedAssets'
71
+ end
72
+
73
+ describe 'Rais 5.x' do
74
+ before do
75
+ allow(app).to receive(:rails_version_5?) { true }
76
+ end
77
+
78
+ it_behaves_like 'ServeZippedAssets'
79
+ end
80
+ end
@@ -0,0 +1,40 @@
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
+ expect(headers['Cache-Control'].to_s).to 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 application/vnd.api+json].each do |type|
25
+ headers = process(type)
26
+ expect(headers['Cache-Control'].to_s).not_to include('no-transform')
27
+ end
28
+ end
29
+
30
+ it "adds to existing headers" do
31
+ headers = process('image/gif', 'Cache-Control' => 'public')
32
+ expect(headers['Cache-Control']).to 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
+ expect(headers['Cache-Control']).to eq('public, no-transform')
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tome-oauth-io-bible-heroku-deflater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Shterenzon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Fork heroku-deflater with fixes for custom cache expiration time setting
84
+ email: romanbsd@yahoo.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.md
90
+ files:
91
+ - ".rspec"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - VERSION
98
+ - heroku-deflater.gemspec
99
+ - lib/heroku-deflater.rb
100
+ - lib/heroku-deflater/cache_control_manager.rb
101
+ - lib/heroku-deflater/railtie.rb
102
+ - lib/heroku-deflater/serve_zipped_assets.rb
103
+ - lib/heroku-deflater/skip_binary.rb
104
+ - spec/cache_control_manager_spec.rb
105
+ - spec/fixtures/assets/spec.js
106
+ - spec/fixtures/assets/spec.js.gz
107
+ - spec/fixtures/assets/spec2.js
108
+ - spec/fixtures/non-assets/spec.js.gz
109
+ - spec/serve_zipped_assets_spec.rb
110
+ - spec/skip_binary_spec.rb
111
+ homepage: http://github.com/romanbsd/heroku-deflater
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.7.7
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Deflate assets on heroku
135
+ test_files: []