agouti 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/agouti/rack/package_limiter.rb +18 -11
- data/lib/agouti/version.rb +1 -1
- data/spec/rack/package_limiter_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01b7db6614008d1aff38366c1a91557afb6fd75e
|
4
|
+
data.tar.gz: 0ccc48a55e09512ccddad67e3d74800dbeb971a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864cb988390b4f297e19c9ef0fe694c6d887323e7f582e33ac92e9a257408f2c8bc12690224823968e925271c82e359ce5429488e418bfc68cd4fcc000c79c5e
|
7
|
+
data.tar.gz: de652806d32533f7dfdc32e4416214d6eb4bea9aaa6ba5a965e328c653a1910210c2a1c1dc16dc311556432f2d1e9aa1161b89fc241e7a0caf8a604e47dffdf4
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -48,7 +48,7 @@ module Agouti
|
|
48
48
|
set_limit(env)
|
49
49
|
|
50
50
|
if enabled?(env)
|
51
|
-
unless headers['Content-Type']
|
51
|
+
unless headers['Content-Type'] && headers['Content-Type'].include?('text/html')
|
52
52
|
return [204, {}, []]
|
53
53
|
end
|
54
54
|
|
@@ -71,27 +71,34 @@ module Agouti
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def enabled? env
|
74
|
-
get_http_header(env, ENABLE_HEADER)
|
74
|
+
get_http_header(env, ENABLE_HEADER).to_i == 1
|
75
75
|
end
|
76
76
|
|
77
77
|
def set_limit env
|
78
78
|
@limit = (get_http_header(env, LIMIT_HEADER)) ? get_http_header(env, LIMIT_HEADER).to_i : DEFAULT_LIMIT
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
82
|
-
|
81
|
+
def valid? env
|
82
|
+
valid_enable_header?(env) && valid_limit_header?(env)
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
+
def parseable?(header)
|
86
|
+
(header =~ /^[0-9]+$/) == 0
|
85
87
|
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
+
# Defines two methods: valid_enable_header? and valid_limit_header?
|
90
|
+
['enable', 'limit'].each do |action|
|
91
|
+
define_method("valid_#{action}_header?") do |env|
|
92
|
+
header = get_http_header(env, self.class.const_get("#{action.upcase}_HEADER"))
|
89
93
|
|
90
|
-
|
91
|
-
end
|
94
|
+
return true if header.nil?
|
92
95
|
|
93
|
-
|
94
|
-
|
96
|
+
if parseable?(header)
|
97
|
+
header.to_i >= 0
|
98
|
+
else
|
99
|
+
false
|
100
|
+
end
|
101
|
+
end
|
95
102
|
end
|
96
103
|
|
97
104
|
# Public: class responsible for truncating the gzip stream to a given number of bytes.
|
data/lib/agouti/version.rb
CHANGED
@@ -11,8 +11,8 @@ describe Agouti::Rack::PackageLimiter do
|
|
11
11
|
context 'when header X-Agouti-Enable is set' do
|
12
12
|
|
13
13
|
context 'when header X-Agouti-Enable is set with 1' do
|
14
|
-
let(:headers) { { 'X-Agouti-Enable' => 1 } }
|
15
|
-
let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => 1 } }
|
14
|
+
let(:headers) { { 'X-Agouti-Enable' => '1' } }
|
15
|
+
let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => '1' } }
|
16
16
|
|
17
17
|
context 'when the request response is not an html' do
|
18
18
|
it 'returns status code 204' do
|
@@ -37,8 +37,8 @@ describe Agouti::Rack::PackageLimiter do
|
|
37
37
|
|
38
38
|
context 'when header X-Agouti-Limit is set with a valid number of bytes' do
|
39
39
|
it 'returns gzipped data with given number of bytes' do
|
40
|
-
headers.merge!('X-Agouti-Limit' => 10, 'Content-Type' => 'text/html')
|
41
|
-
env.merge!('HTTP_X_AGOUTI_LIMIT' => 10)
|
40
|
+
headers.merge!('X-Agouti-Limit' => '10', 'Content-Type' => 'text/html')
|
41
|
+
env.merge!('HTTP_X_AGOUTI_LIMIT' => '10')
|
42
42
|
|
43
43
|
response_status, response_headers, response_body = subject
|
44
44
|
|
@@ -61,8 +61,8 @@ describe Agouti::Rack::PackageLimiter do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'when header X-Agouti-Enable is set with 0' do
|
64
|
-
let(:headers) { { 'X-Agouti-Enable' => 0 } }
|
65
|
-
let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => 0 } }
|
64
|
+
let(:headers) { { 'X-Agouti-Enable' => '0' } }
|
65
|
+
let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => '0' } }
|
66
66
|
|
67
67
|
it 'does nothing' do
|
68
68
|
expect(subject). to match_array([200, headers, []])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agouti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dwayhs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|