rack_deflater_bypass 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +20 -0
- data/README.md +25 -0
- data/Rakefile +47 -0
- data/lib/rack_deflater_bypass.rb +21 -0
- data/rack_deflater_bypass.gemspec +65 -0
- data/spec/rack_deflater_bypass_spec.rb +57 -0
- data/spec/spec_helper.rb +7 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fd0f2c4ebc5ffb54a27c790d721fa52dc13d6f47
|
4
|
+
data.tar.gz: d22459a114527a2358846f550e6ffbc0cdbb636b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84c69ef2e71b9cae077d777deb63989f5602c30cd09115ea4772e76a5884c709aa33b6efe3bc8457efb5db33500b03a3d5e85327b4e7d5c3f920fc84a61460d6
|
7
|
+
data.tar.gz: 14d0b195c8dbcaa2224c69b9d78a99cdfec48e1ce8a760e605d9baf81214f574efe5594e5c7f5106214290b016d9fe963b17888109ce8d58e004499df4ffee54
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Add dependencies to develop your gem here.
|
4
|
+
# Include everything needed to run rake, tests, features, etc.
|
5
|
+
group :development do
|
6
|
+
gem "rack"
|
7
|
+
gem "rspec", "~> 3"
|
8
|
+
gem 'rack-test'
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", "~> 1.0"
|
11
|
+
gem "jeweler"
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Julik Tarkhanov
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# rack_deflater_bypass
|
2
|
+
|
3
|
+
Ensures that if you send a .gz file from your Rack stack `Rack::Deflate` will not try to recompress
|
4
|
+
it and damage the headers in a way that confuses old browsers.
|
5
|
+
|
6
|
+
To use, just add it to your Rack stack __instead of Rack::Deflate__
|
7
|
+
|
8
|
+
# config.ru
|
9
|
+
use RackDeflaterBypass
|
10
|
+
|
11
|
+
## Contributing to rack_deflater_bypass
|
12
|
+
|
13
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
14
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
15
|
+
* Fork the project.
|
16
|
+
* Start a feature/bugfix branch.
|
17
|
+
* Commit and push until you are happy with your contribution.
|
18
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
19
|
+
* 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.
|
20
|
+
|
21
|
+
## Copyright
|
22
|
+
|
23
|
+
Copyright (c) 2015 Julik Tarkhanov. See LICENSE.txt for
|
24
|
+
further details.
|
25
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
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 File.dirname(__FILE__) + '/lib/rack_deflater_bypass'
|
15
|
+
|
16
|
+
require 'jeweler'
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
19
|
+
gem.version = RackDeflaterBypass::VERSION
|
20
|
+
gem.name = "rack_deflater_bypass"
|
21
|
+
gem.homepage = "http://github.com/julik/rack_deflater_bypass"
|
22
|
+
gem.license = "MIT"
|
23
|
+
gem.summary = %Q{Bypass Rack::Deflate for raw compressed responses}
|
24
|
+
gem.description = %Q{Useful for serving tarballs via Rack}
|
25
|
+
gem.email = "me@julik.nl"
|
26
|
+
gem.authors = ["Julik Tarkhanov"]
|
27
|
+
# dependencies defined in Gemfile
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rspec/core'
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
34
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rdoc/task'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "rack_deflater_bypass #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Wrapper for Rack::Deflater that will prevent
|
2
|
+
# the said Deflater from EVER touching .tgz files
|
3
|
+
class RackDeflaterBypass
|
4
|
+
VERSION = '0.0.1'
|
5
|
+
BYPASS_FILES = /\.(t?)gz$/
|
6
|
+
|
7
|
+
# bypass_url_regexp will be matched against PATH_INFO
|
8
|
+
def initialize(app, bypass_url_regexp = BYPASS_FILES)
|
9
|
+
@bypass_url_regexp = bypass_url_regexp
|
10
|
+
@app = app
|
11
|
+
@deflater = Rack::Deflater.new(@app)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if env['PATH_INFO'] =~ @bypass_url_regexp
|
16
|
+
@app.call(env)
|
17
|
+
else
|
18
|
+
@deflater.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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: rack_deflater_bypass 0.0.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rack_deflater_bypass"
|
9
|
+
s.version = "0.0.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Julik Tarkhanov"]
|
14
|
+
s.date = "2015-05-06"
|
15
|
+
s.description = "Useful for serving tarballs via Rack"
|
16
|
+
s.email = "me@julik.nl"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"lib/rack_deflater_bypass.rb",
|
29
|
+
"rack_deflater_bypass.gemspec",
|
30
|
+
"spec/rack_deflater_bypass_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = "http://github.com/julik/rack_deflater_bypass"
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.rubygems_version = "2.2.0"
|
36
|
+
s.summary = "Bypass Rack::Deflate for raw compressed responses"
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
s.specification_version = 4
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_development_dependency(%q<rack>, [">= 0"])
|
43
|
+
s.add_development_dependency(%q<rspec>, ["~> 3"])
|
44
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
50
|
+
s.add_dependency(%q<rspec>, ["~> 3"])
|
51
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rspec>, ["~> 3"])
|
59
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'rack'
|
3
|
+
require 'rack/lobster'
|
4
|
+
|
5
|
+
describe "RackDeflaterBypass" do
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
tgz = lambda {|_| [200, {'Content-Type'=>'text/plain'}, ["Hello from .tgz"]]}
|
10
|
+
|
11
|
+
Rack::Builder.new do | b |
|
12
|
+
use RackDeflaterBypass
|
13
|
+
|
14
|
+
b.map '/lobster' do
|
15
|
+
run Rack::Lobster.new
|
16
|
+
end
|
17
|
+
|
18
|
+
b.map '/lobster.agz' do
|
19
|
+
run Rack::Lobster.new
|
20
|
+
end
|
21
|
+
|
22
|
+
b.map '/geezip.tgz' do
|
23
|
+
run tgz
|
24
|
+
end
|
25
|
+
|
26
|
+
b.map '/geezip.tar.gz' do
|
27
|
+
run tgz
|
28
|
+
end
|
29
|
+
end.to_app
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'allows Deflate to compress when Accept-Encoding is set to gzip' do
|
33
|
+
get '/lobster', {}, {"HTTP_ACCEPT_ENCODING" => "gzip"}
|
34
|
+
ref = {"Vary"=>"Accept-Encoding", "Content-Encoding"=>"gzip", "Content-Length"=>"288"}
|
35
|
+
expect(last_response.headers).to eq(ref)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'allows Deflate to compress with hypothetical "agz" extension' do
|
39
|
+
get '/lobster.agz', {}, {"HTTP_ACCEPT_ENCODING" => "gzip"}
|
40
|
+
ref = {"Vary"=>"Accept-Encoding", "Content-Encoding"=>"gzip", "Content-Length"=>"288"}
|
41
|
+
expect(last_response.headers).to eq(ref)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'bypasses Deflate when the request URI has .tgz extension' do
|
45
|
+
get '/geezip.tgz', {}, {"HTTP_ACCEPT_ENCODING" => "gzip"}
|
46
|
+
expect(last_response.headers['Vary']).to be_nil
|
47
|
+
expect(last_response.headers['Content-Encoding']).to be_nil, 'Should have not set Content-Encoding'
|
48
|
+
expect(last_response.body).to eq("Hello from .tgz"), 'Should have passed the body unencoded'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'bypasses Deflate when the request URI has .gz extension' do
|
52
|
+
get '/geezip.tar.gz', {}, {"HTTP_ACCEPT_ENCODING" => "gzip"}
|
53
|
+
expect(last_response.headers['Vary']).to be_nil
|
54
|
+
expect(last_response.headers['Content-Encoding']).to be_nil, 'Should have not set Content-Encoding'
|
55
|
+
expect(last_response.body).to eq("Hello from .tgz"), 'Should have passed the body unencoded'
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_deflater_bypass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julik Tarkhanov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-06 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
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: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Useful for serving tarballs via Rack
|
98
|
+
email: me@julik.nl
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
files:
|
105
|
+
- ".document"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/rack_deflater_bypass.rb
|
112
|
+
- rack_deflater_bypass.gemspec
|
113
|
+
- spec/rack_deflater_bypass_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
homepage: http://github.com/julik/rack_deflater_bypass
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.0
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Bypass Rack::Deflate for raw compressed responses
|
139
|
+
test_files: []
|