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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d17f0629b61d4802b40da6dd088ab82277c09412
4
- data.tar.gz: 3f0fb225709a01983227b70f014985505e324a13
3
+ metadata.gz: 46245a6fd2928c5cec7960b2e5b4890ec8b98de1
4
+ data.tar.gz: 6e39e8cb91a529be5676dbc5301c570de3d43819
5
5
  SHA512:
6
- metadata.gz: 1c2af2da13f9473883c6868aeac25763229da118e9f7d0eac8c7284cf6396a6a9d6512e8fb6261d8dd02a00f5a72ae60b6e585baf911edb8a37b50ea4d53daf5
7
- data.tar.gz: 7c7bf53188977357a6a3bd7daaaf123886328d0653b2d3555a8072ec54dcdcf286484ed0200945d9b9ec6ecab93d7540f816c2fb516d515a1b66e0f6563b57a0
6
+ metadata.gz: fc4823c8cb10eac9092438053bd0dc41dbaaed15986579c76944e8ea8cdfb005fda8a8e969fd24de15ee5c26e9e20632eae269e11d8cacda98a9b3ac69076851
7
+ data.tar.gz: 6c64b98531e5dcbccfb0081415dcf7babb66f9d77fd828d1923e5a285bf4cc2bc36dcbea6ec8e878f1f731dbfef0f12bedc172ce4c5e635b461eb6d4b646f247
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
6
+ - rbx-19mode
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
- Unfortunately, `Rack::Static` is hardcoded to use `Rack::File`. [Hopefully this will be changed](https://github.com/rack/rack/pull/479#issuecomment-21907789), but in the meantime you can do an ugly monkey patch like this:
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
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = %w(--color)
6
+ end
7
+
8
+ task default: 'spec'
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class GzFile
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -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
@@ -1,2 +1,3 @@
1
1
  require "rack/gz_file"
2
2
  require "rack/gz_file/version"
3
+ require "rack/static_decorator"
@@ -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.1.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