rack-zippy 1.0.1 → 1.1.0
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.
- data/CHANGELOG.md +4 -0
- data/README.md +14 -2
- data/lib/rack-zippy.rb +32 -27
- data/lib/rack-zippy/version.rb +1 -1
- data/test/asset_server_test.rb +24 -20
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 1.1.0 / 2014-01-26
|
2
|
+
- rack-zippy no longer blocks requests for assets that it cannot find on the filesystem. These
|
3
|
+
requests are now passed on to the app. ([#7](https://github.com/eliotsykes/rack-zippy/issues/7))
|
4
|
+
|
1
5
|
## 1.0.1 / 2013-09-06
|
2
6
|
- Fix error on request for assets root dir (fixes [#2](https://github.com/eliotsykes/rack-zippy/issues/2))
|
3
7
|
- Add MIT license to gemspec (fixes [#1](https://github.com/eliotsykes/rack-zippy/issues/1))
|
data/README.md
CHANGED
@@ -9,6 +9,10 @@ rack-zippy replaces the ActionDispatch::Static middleware used by Rails, which i
|
|
9
9
|
the `rake assets:precompile` task. rack-zippy will serve non-gzipped assets where they are not available or not supported by the
|
10
10
|
requesting client.
|
11
11
|
|
12
|
+
For a fuller explanation of the how, why, and the kind of performance difference you can expect when using rack-zippy,
|
13
|
+
see [Serving Compressed Assets with Heroku and Rack-Zippy](http://www.cheynewallace.com/serving-compressed-assets-with-heroku-rack-zippy/)
|
14
|
+
(thanks to Cheyne Wallace).
|
15
|
+
|
12
16
|
## Installation
|
13
17
|
|
14
18
|
Add this line to your application's Gemfile:
|
@@ -28,6 +32,14 @@ Add this line to config/application.rb:
|
|
28
32
|
Follow the installation instructions above and rack-zippy will serve any static assets, including gzipped assets, from your
|
29
33
|
application's public/ directory and will respond with sensible caching headers.
|
30
34
|
|
35
|
+
## Troubleshooting
|
36
|
+
|
37
|
+
##### 'assert_index': No such middleware to insert before: ActionDispatch::Static (RuntimeError)
|
38
|
+
|
39
|
+
Check your environment (in config/environments/) does not have `serve_static_assets` set to false:
|
40
|
+
|
41
|
+
config.serve_static_assets = false # Oops! Should be set to true for rack-zippy
|
42
|
+
|
31
43
|
## Contributing
|
32
44
|
|
33
45
|
1. Fork it
|
@@ -39,9 +51,9 @@ application's public/ directory and will respond with sensible caching headers.
|
|
39
51
|
|
40
52
|
## Releasing a new gem
|
41
53
|
|
42
|
-
1.
|
54
|
+
1. Update pre-release version to the release version in lib/rack-zippy/version.rb, e.g. '1.0.1.pre' becomes '1.0.1'
|
43
55
|
2. Update CHANGELOG.md
|
44
56
|
3. Tests pass? (`rake test`)
|
45
57
|
4. Build the gem (`rake build`)
|
46
58
|
5. Release on rubygems.org (`rake release`)
|
47
|
-
|
59
|
+
6. Update version to the next pre-release version in lib/rack-zippy/version.rb, e.g. '1.0.1' becomes '1.0.2.pre'
|
data/lib/rack-zippy.rb
CHANGED
@@ -14,33 +14,25 @@ module Rack
|
|
14
14
|
assert_legal_path path_info
|
15
15
|
|
16
16
|
if serve?(path_info)
|
17
|
+
headers = { 'Content-Type' => Rack::Mime.mime_type(::File.extname(path_info)) }
|
18
|
+
headers.merge! cache_headers(path_info)
|
17
19
|
|
18
|
-
file_path =
|
20
|
+
file_path = path_to_file(path_info)
|
21
|
+
gzipped_file_path = "#{file_path}.gz"
|
22
|
+
gzipped_file_present = ::File.exists?(gzipped_file_path) && ::File.readable?(gzipped_file_path)
|
19
23
|
|
20
|
-
if
|
21
|
-
headers =
|
22
|
-
headers.merge! cache_headers(path_info)
|
24
|
+
if gzipped_file_present
|
25
|
+
headers['Vary'] = 'Accept-Encoding'
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if gzipped_file_present
|
28
|
-
headers['Vary'] = 'Accept-Encoding'
|
29
|
-
|
30
|
-
if client_accepts_gzip?(env)
|
31
|
-
file_path = gzipped_file_path
|
32
|
-
headers['Content-Encoding'] = 'gzip'
|
33
|
-
end
|
27
|
+
if client_accepts_gzip?(env)
|
28
|
+
file_path = gzipped_file_path
|
29
|
+
headers['Content-Encoding'] = 'gzip'
|
34
30
|
end
|
35
|
-
|
36
|
-
status = 200
|
37
|
-
headers['Content-Length'] = ::File.size(file_path).to_s
|
38
|
-
response_body = [::File.read(file_path)]
|
39
|
-
else
|
40
|
-
status = 404
|
41
|
-
headers = {}
|
42
|
-
response_body = ['Not Found']
|
43
31
|
end
|
32
|
+
|
33
|
+
status = 200
|
34
|
+
headers['Content-Length'] = ::File.size(file_path).to_s
|
35
|
+
response_body = [::File.read(file_path)]
|
44
36
|
return [status, headers, response_body]
|
45
37
|
end
|
46
38
|
|
@@ -84,15 +76,28 @@ module Rack
|
|
84
76
|
return headers
|
85
77
|
end
|
86
78
|
|
79
|
+
def path_to_file(path_info)
|
80
|
+
"#{@asset_root}#{path_info}"
|
81
|
+
end
|
82
|
+
|
87
83
|
def serve?(path_info)
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
should_serve_from_filesystem = false
|
85
|
+
|
86
|
+
if has_static_extension?(path_info)
|
87
|
+
file_path = path_to_file(path_info)
|
88
|
+
is_serveable = ::File.file?(file_path) && ::File.readable?(file_path)
|
89
|
+
|
90
|
+
if is_serveable
|
91
|
+
is_outside_assets_dir = !(path_info =~ PRECOMPILED_ASSETS_SUBDIR_REGEX)
|
92
|
+
should_serve_from_filesystem = is_outside_assets_dir || block_asset_pipeline_from_generating_asset?
|
93
|
+
end
|
91
94
|
end
|
92
|
-
|
95
|
+
|
96
|
+
return should_serve_from_filesystem
|
93
97
|
end
|
94
98
|
|
95
|
-
def
|
99
|
+
def block_asset_pipeline_from_generating_asset?
|
100
|
+
# config.assets.compile is normally false in production, and true in dev+test envs.
|
96
101
|
!::Rails.configuration.assets.compile
|
97
102
|
end
|
98
103
|
|
data/lib/rack-zippy/version.rb
CHANGED
data/test/asset_server_test.rb
CHANGED
@@ -25,28 +25,28 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
|
|
25
25
|
assert_underlying_app_responded
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def test_request_for_subdir_of_assets_passed_onto_app
|
29
29
|
['/assets/blog', '/assets/blog/logos/'].each do |path|
|
30
30
|
local_path = "public#{path}"
|
31
31
|
assert File.directory?(local_path)
|
32
32
|
get path
|
33
|
-
|
33
|
+
assert_underlying_app_responded
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def test_request_for_non_existent_subdir_of_assets_passed_onto_app
|
38
38
|
['/assets/ghost', '/assets/does/not/exist', '/assets/nothing-here/with-trailing-slash/'].each do |path|
|
39
39
|
local_path = "public#{path}"
|
40
40
|
assert !File.exists?(local_path)
|
41
41
|
get path
|
42
|
-
|
42
|
+
assert_underlying_app_responded
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def test_request_for_assets_root_passed_onto_app
|
47
47
|
['/assets/', '/assets'].each do |assets_root|
|
48
48
|
get assets_root
|
49
|
-
|
49
|
+
assert_underlying_app_responded
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -68,8 +68,12 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
|
|
68
68
|
assert_underlying_app_responded
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
72
|
-
assert app.send(:serve?, '/
|
71
|
+
def test_serve_returns_true_if_request_has_static_extension_and_file_exists
|
72
|
+
assert app.send(:serve?, '/thanks.html')
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_serve_returns_false_if_request_has_static_extension_and_file_does_not_exist
|
76
|
+
assert !app.send(:serve?, '/about.html')
|
73
77
|
end
|
74
78
|
|
75
79
|
def test_serve_returns_false_if_request_does_not_have_static_extension
|
@@ -85,15 +89,15 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
|
|
85
89
|
assert !app.send(:serve?, '/assets/application.css')
|
86
90
|
end
|
87
91
|
|
88
|
-
def
|
92
|
+
def test_block_asset_pipeline_from_generating_asset_returns_false_if_assets_compile_enabled
|
89
93
|
::Rails.configuration.assets.compile = true
|
90
94
|
assert ::Rails.configuration.assets.compile
|
91
|
-
assert !app.send(:
|
95
|
+
assert !app.send(:block_asset_pipeline_from_generating_asset?)
|
92
96
|
end
|
93
97
|
|
94
|
-
def
|
98
|
+
def test_block_asset_pipeline_from_generating_asset_returns_true_if_assets_compile_disabled
|
95
99
|
assert !::Rails.configuration.assets.compile
|
96
|
-
assert app.send(:
|
100
|
+
assert app.send(:block_asset_pipeline_from_generating_asset?)
|
97
101
|
end
|
98
102
|
|
99
103
|
def test_responds_with_gzipped_css_to_gzip_capable_clients
|
@@ -231,9 +235,9 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
|
|
231
235
|
assert_underlying_app_responded
|
232
236
|
end
|
233
237
|
|
234
|
-
def
|
238
|
+
def test_passes_not_found_asset_requests_onto_app
|
235
239
|
get '/index.html'
|
236
|
-
|
240
|
+
assert_underlying_app_responded
|
237
241
|
end
|
238
242
|
|
239
243
|
def test_responds_with_favicon_in_assets_dir
|
@@ -250,19 +254,19 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
|
|
250
254
|
assert_content_length 'public/favicon.ico'
|
251
255
|
end
|
252
256
|
|
253
|
-
def
|
257
|
+
def test_request_for_non_existent_image_passed_onto_app
|
254
258
|
get '/assets/pot-of-gold.png'
|
255
|
-
|
259
|
+
assert_underlying_app_responded
|
256
260
|
end
|
257
261
|
|
258
|
-
def
|
262
|
+
def test_request_for_non_existent_css_passed_onto_app
|
259
263
|
get '/assets/unicorn.css'
|
260
|
-
|
264
|
+
assert_underlying_app_responded
|
261
265
|
end
|
262
266
|
|
263
|
-
def
|
267
|
+
def test_request_for_non_existent_js_passed_onto_app
|
264
268
|
get '/assets/dragon.js'
|
265
|
-
|
269
|
+
assert_underlying_app_responded
|
266
270
|
end
|
267
271
|
|
268
272
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-zippy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Rack middleware for serving static gzipped assets generated by the Rails
|
15
15
|
asset pipeline
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash:
|
58
|
+
hash: 2781769223884308970
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash:
|
67
|
+
hash: 2781769223884308970
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
70
|
rubygems_version: 1.8.23
|