improved-rack-throttle 0.8.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dea077855e9d5f1e7aa8126af311c58f518e2abf
4
- data.tar.gz: d1c0ce949e3a7152adfb1b9b6ae96896021d5e81
3
+ metadata.gz: de9d89ff0b5442cec2f406a016bce0ff6d97b308
4
+ data.tar.gz: 022ac60a09f2655dcf993b8892c2605aeb278884
5
5
  SHA512:
6
- metadata.gz: 77a62c9ad00ee3aff04a413e5e186a261cd925c9b46e281dd167604fee5b3df2451daf4eb775f1c3b94a4b1e1fb16feddd35828763ed33666dc62df7c5bfc6cb
7
- data.tar.gz: ab2f078f3380a13826fbb30f47292540ae59c8cf3269f1fa4ce051825962574d7d9e6021709058381dabb7035cd610b4ce05d2575e57f196292abb4aa00bde8f
6
+ metadata.gz: 96c2e827d860790ced263b32bebfaeb87d08c5de1a24531d09ed03fbdcd904ea9e2811b499332add090385b24923830b1de8a7e27536e7a6ed0db4bee5b30390
7
+ data.tar.gz: 4e68494c77b26233c22bdfa50c13ba1273b7da107399db3663c4ad025bd439366273761962582932910a32fe9cb4687ddde641b8c80d305002940d9aa7ce8538
data/Gemfile.lock CHANGED
@@ -1,40 +1,75 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
4
8
  diff-lcs (1.2.5)
5
- git (1.2.5)
6
- jeweler (1.8.4)
7
- bundler (~> 1.0)
9
+ docile (1.1.5)
10
+ faraday (0.9.1)
11
+ multipart-post (>= 1.2, < 3)
12
+ git (1.2.9.1)
13
+ github_api (0.12.2)
14
+ addressable (~> 2.3)
15
+ descendants_tracker (~> 0.0.4)
16
+ faraday (~> 0.8, < 0.10)
17
+ hashie (>= 3.3)
18
+ multi_json (>= 1.7.5, < 2.0)
19
+ nokogiri (~> 1.6.3)
20
+ oauth2
21
+ hashie (3.3.2)
22
+ highline (1.6.21)
23
+ jeweler (2.0.1)
24
+ builder
25
+ bundler (>= 1.0)
8
26
  git (>= 1.2.5)
27
+ github_api
28
+ highline (>= 1.6.15)
29
+ nokogiri (>= 1.5.10)
9
30
  rake
10
31
  rdoc
11
- json (1.8.0)
12
- multi_json (1.7.6)
13
- rack (1.5.2)
14
- rack-test (0.6.2)
32
+ json (1.8.2)
33
+ jwt (1.2.1)
34
+ mini_portile (0.6.2)
35
+ multi_json (1.10.1)
36
+ multi_xml (0.5.5)
37
+ multipart-post (2.0.0)
38
+ nokogiri (1.6.6.2)
39
+ mini_portile (~> 0.6.0)
40
+ oauth2 (1.0.0)
41
+ faraday (>= 0.8, < 0.10)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ rack (1.6.0)
47
+ rack-test (0.6.3)
15
48
  rack (>= 1.0)
16
- rake (10.0.4)
17
- rdoc (4.0.1)
49
+ rake (10.4.2)
50
+ rdoc (4.2.0)
18
51
  json (~> 1.4)
19
- redcarpet (2.3.0)
20
- rspec (3.0.0)
21
- rspec-core (~> 3.0.0)
22
- rspec-expectations (~> 3.0.0)
23
- rspec-mocks (~> 3.0.0)
24
- rspec-core (3.0.1)
25
- rspec-support (~> 3.0.0)
26
- rspec-expectations (3.0.1)
52
+ redcarpet (3.2.2)
53
+ rspec (3.1.0)
54
+ rspec-core (~> 3.1.0)
55
+ rspec-expectations (~> 3.1.0)
56
+ rspec-mocks (~> 3.1.0)
57
+ rspec-core (3.1.7)
58
+ rspec-support (~> 3.1.0)
59
+ rspec-expectations (3.1.2)
27
60
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.0.0)
29
- rspec-mocks (3.0.1)
30
- rspec-support (~> 3.0.0)
31
- rspec-support (3.0.0)
32
- simplecov (0.7.1)
61
+ rspec-support (~> 3.1.0)
62
+ rspec-mocks (3.1.3)
63
+ rspec-support (~> 3.1.0)
64
+ rspec-support (3.1.2)
65
+ simplecov (0.9.1)
66
+ docile (~> 1.1.0)
33
67
  multi_json (~> 1.0)
34
- simplecov-html (~> 0.7.1)
35
- simplecov-html (0.7.1)
36
- timecop (0.6.1)
37
- yard (0.8.6.1)
68
+ simplecov-html (~> 0.8.0)
69
+ simplecov-html (0.8.0)
70
+ thread_safe (0.3.4)
71
+ timecop (0.6.2.2)
72
+ yard (0.8.7.6)
38
73
 
39
74
  PLATFORMS
40
75
  ruby
data/README.md CHANGED
@@ -66,6 +66,12 @@ Examples
66
66
 
67
67
  use Rack::Throttle::Interval, :min => 3.0
68
68
 
69
+ ### Allowing a maximum of 100 requests per hour, for the foo basic auth
70
+ user
71
+
72
+ use Rack::Throttle::Hourly, :max => 100, :rules => {:basic_auth =>
73
+ /foo/}
74
+
69
75
  ### Allowing a maximum of 100 requests per hour
70
76
 
71
77
  use Rack::Throttle::Hourly, :max => 100
@@ -200,6 +206,7 @@ Documentation
200
206
  * {Rack::Throttle::MethodMatcher}
201
207
  * {Rack::Throttle::UrlMatcher}
202
208
  * {Rack::Throttle::UserAgentMatcher}
209
+ * {Rack::Throttle::BasicAuthMatcher}
203
210
 
204
211
  Dependencies
205
212
  ------------
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "improved-rack-throttle"
8
- s.version = "0.8.0"
8
+ s.version = "0.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Somers", "Arto Bendiken", "Brendon Murphy"]
12
- s.date = "2014-09-22"
12
+ s.date = "2015-01-27"
13
13
  s.description = "Rack middleware for rate-limiting incoming HTTP requests."
14
14
  s.email = "somers.ben@gmail.com"
15
15
  s.extra_rdoc_files = [
data/lib/rack/throttle.rb CHANGED
@@ -13,5 +13,6 @@ module Rack
13
13
  autoload :UrlMatcher, 'rack/throttle/matchers/url_matcher'
14
14
  autoload :MethodMatcher, 'rack/throttle/matchers/method_matcher'
15
15
  autoload :UserAgentMatcher, 'rack/throttle/matchers/user_agent_matcher'
16
+ autoload :BasicAuthMatcher, 'rack/throttle/matchers/basic_auth_matcher'
16
17
  end
17
18
  end
@@ -26,6 +26,7 @@ module Rack; module Throttle
26
26
  @matchers += Array(rules[:url]).map { |rule| UrlMatcher.new(rule) } if rules[:url]
27
27
  @matchers += Array(rules[:user_agent]).map { |rule| UserAgentMatcher.new(rule) } if rules[:user_agent]
28
28
  @matchers += Array(rules[:method]).map { |rule| MethodMatcher.new(rule) } if rules[:method]
29
+ @matchers += Array(rules[:basic_auth]).map { |rule| BasicAuthMatcher.new(rule) } if rules[:basic_auth]
29
30
  end
30
31
 
31
32
  ##
@@ -26,14 +26,14 @@ module Rack; module Throttle
26
26
  def allowed?(request)
27
27
  t1 = request_start_time(request)
28
28
  key = cache_key(request)
29
- bucket = cache_get(key) rescue nil
29
+ bucket = Marshal.load(cache_get(key)) rescue nil
30
30
  bucket ||= LeakyBucket.new(options[:burst], options[:average])
31
31
  bucket.maximum, bucket.outflow = options[:burst], options[:average]
32
32
  bucket.leak!
33
33
  bucket.increment!
34
34
  allowed = !bucket.full?
35
35
  begin
36
- cache_set(key, bucket)
36
+ cache_set(key, Marshal.dump(bucket))
37
37
  allowed
38
38
  rescue StandardError => e
39
39
  allowed = true
@@ -1,7 +1,7 @@
1
1
  module Rack; module Throttle
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 8
4
+ MINOR = 9
5
5
  TINY = 0
6
6
  EXTRA = nil
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: improved-rack-throttle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Somers
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-22 00:00:00.000000000 Z
13
+ date: 2015-01-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack