rack_gzfile 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +3 -13
- data/Rakefile +7 -0
- data/lib/rack/gz_file/version.rb +1 -1
- data/lib/rack/static_decorator.rb +11 -0
- data/lib/rack_gzfile.rb +1 -0
- data/spec/lib/rack/static_spec.rb +17 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46245a6fd2928c5cec7960b2e5b4890ec8b98de1
|
4
|
+
data.tar.gz: 6e39e8cb91a529be5676dbc5301c570de3d43819
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc4823c8cb10eac9092438053bd0dc41dbaaed15986579c76944e8ea8cdfb005fda8a8e969fd24de15ee5c26e9e20632eae269e11d8cacda98a9b3ac69076851
|
7
|
+
data.tar.gz: 6c64b98531e5dcbccfb0081415dcf7babb66f9d77fd828d1923e5a285bf4cc2bc36dcbea6ec8e878f1f731dbfef0f12bedc172ce4c5e635b461eb6d4b646f247
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/balexand/rack_gzfile.png)](https://travis-ci.org/balexand/rack_gzfile)
|
2
|
+
|
1
3
|
# RackGzfile
|
2
4
|
|
3
5
|
By default, `rake assets:precompile` generates gzipped versions of certain types of files. Servers (like Nginx with the GzipStatic module) can then serve these gzipped assets so they can get the reduced bandwidth of gzip without needing to compress the file on every request. [This pull request](https://github.com/rack/rack/pull/479) will hopefully bring this functionality to Rack. In the meantime, this gem can be used.
|
@@ -18,19 +20,7 @@ And then execute:
|
|
18
20
|
|
19
21
|
### Usage with `Rack::Static`
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
Rack::Static.class_eval do
|
25
|
-
def initialize_with_gzip_file_server(app, options={})
|
26
|
-
initialize_without_gzip_file_server(app, options)
|
27
|
-
|
28
|
-
root = options[:root] || Dir.pwd
|
29
|
-
@file_server = Rack::GzFile.new(root, @headers)
|
30
|
-
end
|
31
|
-
alias_method_chain :initialize, :gzip_file_server
|
32
|
-
end
|
33
|
-
```
|
23
|
+
By default, this gem monkey patches `Rack::Static` to use gzip. All that you need to do is require the gem.
|
34
24
|
|
35
25
|
## Contributing
|
36
26
|
|
data/Rakefile
CHANGED
data/lib/rack/gz_file/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rack/static'
|
2
|
+
|
3
|
+
Rack::Static.class_eval do
|
4
|
+
alias_method :initialize_without_gzip_file_server, :initialize
|
5
|
+
def initialize(app, options={})
|
6
|
+
initialize_without_gzip_file_server(app, options)
|
7
|
+
|
8
|
+
root = options[:root] || Dir.pwd
|
9
|
+
@file_server = Rack::GzFile.new(root, @headers)
|
10
|
+
end
|
11
|
+
end
|
data/lib/rack_gzfile.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::Static do
|
4
|
+
|
5
|
+
let(:root) { File.expand_path("../../../fixtures", __FILE__) }
|
6
|
+
let(:request) { Rack::MockRequest.new(Rack::Lint.new(Rack::Static.new(nil, urls: ['/'], root: root))) }
|
7
|
+
|
8
|
+
it "renders gzipped content" do
|
9
|
+
res = request.get('/i_can_has_gzip.html', 'HTTP_ACCEPT_ENCODING' => 'gzip')
|
10
|
+
expect(res.status).to eq 200
|
11
|
+
expect(Zlib::GzipReader.new(StringIO.new(res.body)).read).to eq "I can has gzip!\n"
|
12
|
+
expect(res.headers['Content-Encoding']).to eq 'gzip'
|
13
|
+
expect(res.headers['Vary']).to eq 'Accept-Encoding'
|
14
|
+
expect(res.headers['Content-Length']).to eq File.size(File.join(root, "i_can_has_gzip.html.gz")).to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_gzfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Alexander
|
@@ -74,18 +74,21 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
|
+
- .travis.yml
|
77
78
|
- Gemfile
|
78
79
|
- LICENSE.txt
|
79
80
|
- README.md
|
80
81
|
- Rakefile
|
81
82
|
- lib/rack/gz_file.rb
|
82
83
|
- lib/rack/gz_file/version.rb
|
84
|
+
- lib/rack/static_decorator.rb
|
83
85
|
- lib/rack_gzfile.rb
|
84
86
|
- rack_gzfile.gemspec
|
85
87
|
- spec/fixtures/foo.html
|
86
88
|
- spec/fixtures/i_can_has_gzip.html
|
87
89
|
- spec/fixtures/i_can_has_gzip.html.gz
|
88
90
|
- spec/lib/rack/gz_file_spec.rb
|
91
|
+
- spec/lib/rack/static_spec.rb
|
89
92
|
- spec/spec_helper.rb
|
90
93
|
homepage: ''
|
91
94
|
licenses:
|
@@ -116,4 +119,5 @@ test_files:
|
|
116
119
|
- spec/fixtures/i_can_has_gzip.html
|
117
120
|
- spec/fixtures/i_can_has_gzip.html.gz
|
118
121
|
- spec/lib/rack/gz_file_spec.rb
|
122
|
+
- spec/lib/rack/static_spec.rb
|
119
123
|
- spec/spec_helper.rb
|