rack-cachely 0.3.4 → 0.4.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.
- checksums.yaml +7 -0
- data/Gemfile.lock +2 -2
- data/README.md +8 -3
- data/lib/rack-cachely/config.rb +6 -2
- data/lib/rack-cachely/key.rb +41 -4
- data/lib/rack-cachely/version.rb +1 -1
- data/spec/rack-cachely/key_spec.rb +20 -1
- metadata +9 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f4080bb9c2d7996d66615deb889c894bbb4899d
|
4
|
+
data.tar.gz: 97b741a1f1b6c746c417066cb8191465f647af0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e95627d21f37a878f4017c57647fb90fc6c51f185631f482d5b3f048562b635bc16e5b77273248d4376991217e5213c079ecae71fb88829e8ee2d4b02cbe4bc
|
7
|
+
data.tar.gz: 9185062d94498de7efa4003205ebd66d0cac8974661f3e94eaabe3e569cc0f59af027c85a36003a8e769585c8ee0bbd6624884fb92b58ecef95cfe50b7aac745
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-cachely (0.
|
4
|
+
rack-cachely (0.4.0)
|
5
5
|
rack
|
6
6
|
|
7
7
|
GEM
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
fakeweb (1.3.0)
|
15
15
|
i18n (0.6.1)
|
16
16
|
multi_json (1.3.6)
|
17
|
-
rack (1.5.
|
17
|
+
rack (1.5.2)
|
18
18
|
rspec (2.11.0)
|
19
19
|
rspec-core (~> 2.11.0)
|
20
20
|
rspec-expectations (~> 2.11.0)
|
data/README.md
CHANGED
@@ -46,14 +46,14 @@ end
|
|
46
46
|
### Detailed Configuration
|
47
47
|
|
48
48
|
```ruby
|
49
|
-
config.middleware.use Rack::Cachely,
|
49
|
+
config.middleware.use Rack::Cachely,
|
50
50
|
# Print debug information out to the log (default is false):
|
51
|
-
verbose: false,
|
51
|
+
verbose: false,
|
52
52
|
# Each Cachely account has a custom URL endpoint.
|
53
53
|
# The URL can be found in your Heroku config or through
|
54
54
|
# your Cachely dashboard. By default it looks for an
|
55
55
|
# ENV variable named CACHELY_URL:
|
56
|
-
cachely_url: ENV["CACHELY_URL"],
|
56
|
+
cachely_url: ENV["CACHELY_URL"],
|
57
57
|
# How long are you willing to wait for requests to the Cachely
|
58
58
|
# service to respond? Default is 1 second.
|
59
59
|
timeout: 1.0
|
@@ -83,3 +83,8 @@ Rack::Cachely::Store.delete("users/\d+")
|
|
83
83
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
84
|
4. Push to the branch (`git push origin my-new-feature`)
|
85
85
|
5. Create new Pull Request
|
86
|
+
|
87
|
+
## Contributors
|
88
|
+
|
89
|
+
* Mark Bates
|
90
|
+
* Tim Raymond
|
data/lib/rack-cachely/config.rb
CHANGED
@@ -5,7 +5,7 @@ module Rack
|
|
5
5
|
attr_accessor :options
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
|
-
self.options = {ignore_query_params: [], timeout: 1.0}
|
8
|
+
self.options = {ignore_query_params: [], allow_query_params: [], timeout: 1.0}
|
9
9
|
options.each do |key, value|
|
10
10
|
self.send("#{key}=", value)
|
11
11
|
end
|
@@ -16,6 +16,10 @@ module Rack
|
|
16
16
|
self.options[:ignore_query_params] = [args].flatten.map {|x| x.downcase}
|
17
17
|
end
|
18
18
|
|
19
|
+
def allow_query_params=(*args)
|
20
|
+
self.options[:allow_query_params] = [args].flatten.map {|x| x.downcase}
|
21
|
+
end
|
22
|
+
|
19
23
|
def method_missing(sym, *args, &block)
|
20
24
|
if /(.+)=$/.match(sym.to_s)
|
21
25
|
self.options[$1.to_sym] = args[0]
|
@@ -39,4 +43,4 @@ module Rack
|
|
39
43
|
|
40
44
|
end
|
41
45
|
end
|
42
|
-
end
|
46
|
+
end
|
data/lib/rack-cachely/key.rb
CHANGED
@@ -43,11 +43,48 @@ module Rack
|
|
43
43
|
# and applying consistent escaping.
|
44
44
|
def query_string
|
45
45
|
return nil if @request.query_string.nil?
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
if whitelist_mode?
|
47
|
+
whitelist(@request.query_string)
|
48
|
+
else
|
49
|
+
blacklist(@request.query_string)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def whitelist(query_string)
|
54
|
+
query_params = deparameterize(query_string)
|
55
|
+
whitelisted_params = query_params.select{|k,v| whitelisted?(k) }
|
56
|
+
parameterize(whitelisted_params)
|
57
|
+
end
|
58
|
+
|
59
|
+
def blacklist(query_string)
|
60
|
+
query_params = deparameterize(query_string)
|
61
|
+
blacklisted_params = query_params.reject{|k,v| blacklisted?(k) }
|
62
|
+
parameterize(blacklisted_params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def parameterize(params)
|
66
|
+
params.map{ |k,v| "#{escape(k)}=#{escape(v)}" }.join('&')
|
67
|
+
end
|
68
|
+
|
69
|
+
def deparameterize(query_string)
|
70
|
+
query_string.split(/[&;] */n).map { |p| unescape(p).split('=', 2) }.sort
|
71
|
+
end
|
72
|
+
|
73
|
+
def whitelisted?(param)
|
74
|
+
Rack::Cachely.config.allow_query_params.include?(param)
|
75
|
+
end
|
76
|
+
|
77
|
+
def blacklisted?(param)
|
78
|
+
["no-cachely", "refresh-cachely", Rack::Cachely.config.ignore_query_params].flatten.include?(param)
|
79
|
+
end
|
80
|
+
|
81
|
+
def whitelist_mode?
|
82
|
+
# Whitelist mode is enabled when the whitelist is the ONLY list set
|
83
|
+
Rack::Cachely.config.ignore_query_params.empty? && Rack::Cachely.config.allow_query_params.any?
|
84
|
+
end
|
49
85
|
|
50
|
-
|
86
|
+
def blacklist_mode?
|
87
|
+
!whitelist_mode?
|
51
88
|
end
|
52
89
|
end
|
53
90
|
|
data/lib/rack-cachely/version.rb
CHANGED
@@ -14,9 +14,28 @@ describe Rack::Cachely::Key do
|
|
14
14
|
|
15
15
|
it "will ignore certain query params" do
|
16
16
|
Rack::Cachely.config.ignore_query_params = ["A", "c"]
|
17
|
+
Rack::Cachely.config.allow_query_params = []
|
17
18
|
key.to_s.should eql("http://example.com/foo/bar?b=B&d=D")
|
18
19
|
end
|
19
20
|
|
21
|
+
it "allows whitelisted query params" do
|
22
|
+
Rack::Cachely.config.ignore_query_params = []
|
23
|
+
Rack::Cachely.config.allow_query_params = ["A", "b"]
|
24
|
+
key.to_s.should eql("http://example.com/foo/bar?a=A&b=B")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "will blacklist query params if both whitelist and blacklist are present" do
|
28
|
+
Rack::Cachely.config.allow_query_params = ["A", "b"]
|
29
|
+
Rack::Cachely.config.ignore_query_params = ["A", "c"]
|
30
|
+
key.to_s.should eql("http://example.com/foo/bar?b=B&d=D")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "will allow all query params when neither blacklist nor whitelist is set" do
|
34
|
+
Rack::Cachely.config.allow_query_params = []
|
35
|
+
Rack::Cachely.config.ignore_query_params = []
|
36
|
+
key.to_s.should eql("http://example.com/foo/bar?a=A&b=B&c=C&d=D")
|
37
|
+
end
|
38
|
+
|
20
39
|
context "no query string" do
|
21
40
|
|
22
41
|
let(:request) { double(scheme: "http", host: "example.com", port: 80, script_name: "/foo", path_info: "/bar", query_string: "") }
|
@@ -29,4 +48,4 @@ describe Rack::Cachely::Key do
|
|
29
48
|
|
30
49
|
end
|
31
50
|
|
32
|
-
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cachely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mark Bates
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rack
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: Rack middleware for interfacing with the Cachely page caching service.
|
@@ -54,27 +51,26 @@ files:
|
|
54
51
|
- spec/spec_helper.rb
|
55
52
|
homepage: http://www.cachelyapp.com
|
56
53
|
licenses: []
|
54
|
+
metadata: {}
|
57
55
|
post_install_message:
|
58
56
|
rdoc_options: []
|
59
57
|
require_paths:
|
60
58
|
- lib
|
61
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
60
|
requirements:
|
64
|
-
- -
|
61
|
+
- - '>='
|
65
62
|
- !ruby/object:Gem::Version
|
66
63
|
version: '0'
|
67
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
65
|
requirements:
|
70
|
-
- -
|
66
|
+
- - '>='
|
71
67
|
- !ruby/object:Gem::Version
|
72
68
|
version: '0'
|
73
69
|
requirements: []
|
74
70
|
rubyforge_project:
|
75
|
-
rubygems_version:
|
71
|
+
rubygems_version: 2.0.3
|
76
72
|
signing_key:
|
77
|
-
specification_version:
|
73
|
+
specification_version: 4
|
78
74
|
summary: Rack middleware for interfacing with the Cachely page caching service.
|
79
75
|
test_files:
|
80
76
|
- spec/rack-cachely/config_spec.rb
|